/* Wordfeud Butler — styles
   Design direction: a calm, warm "board game" feel (cream + forest green, echoing icon.svg)
   rather than the old app's flat blue. Tiles are the centerpiece: rendered as physical
   wood/cream Scrabble-style pieces with a corner point value, in both the rack and the
   "remaining tiles" bag view. Mobile-first single column, letterboxed on wide viewports.
   Theme-aware via prefers-color-scheme (light + dark), no framework, no build step.

   General-purpose tokens (surface/text/border/accent/status colors, shadows) now live in
   shared/web/styles/tokens.css - shared project-wide since the single-PWA work
   (plans/project-wide-pwa.md, decision 4), this being the palette it was built from. What is left
   below is only what is genuinely specific to this app: tile rendering (a physical-piece look,
   not a brand color) and the avatar palette (nothing else uses it). */
@import url("/shared/styles/tokens.css");
@import url("/shared/styles/pull-to-refresh.css");

/* ---------- This app's own tokens ---------- */
:root {
  --tile-from: #fdf7e6;
  --tile-to: #ecd9a4;
  --tile-text: #3d2f14;
  --tile-border: rgba(61, 47, 20, 0.35);
  --tile-blank-from: #f2f1ec;
  --tile-blank-to: #dcd9cd;
  --tile-blank-text: #9a9585;

  --avatar-0: #4c6ef5;
  --avatar-1: #e8590c;
  --avatar-2: #0ca678;
  --avatar-3: #e64980;
  --avatar-4: #7048e8;
  --avatar-5: #f08c00;
  --avatar-6: #1098ad;
  --avatar-7: #e03131;
}

/* Dark tile values apply either from system preference (guarded so an explicit light override via
   data-theme wins over it) or from an explicit dark override - see shared/web/theme.js for how
   data-theme gets set/persisted (localStorage + the top bar's toggle button). The rest of the
   palette's light/dark switching happens inside the imported tokens.css; only tile-* is repeated
   here since it is not shared. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tile-from: #f2e6bd;
    --tile-to: #d8bd7d;
    --tile-text: #3a2c10;
    --tile-border: rgba(0, 0, 0, 0.45);
    --tile-blank-from: #383e33;
    --tile-blank-to: #262b21;
    --tile-blank-text: #8f9789;
  }
}

:root[data-theme="dark"] {
  --tile-from: #f2e6bd;
  --tile-to: #d8bd7d;
  --tile-text: #3a2c10;
  --tile-border: rgba(0, 0, 0, 0.45);
  --tile-blank-from: #383e33;
  --tile-blank-to: #262b21;
  --tile-blank-text: #8f9789;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-frame);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- App shell ---------- */
#app {
  min-height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (min-width: 40rem) {
  #app {
    box-shadow: var(--shadow-md);
    min-height: calc(100dvh - 3rem);
    margin: 1.5rem auto;
    border-radius: 1rem;
    overflow: hidden;
  }
}

.screen {
  flex: 1 1 auto;
  padding: 1rem 1rem 2rem;
}

/* ---------- Version footer ---------- */
/* Fixed to the viewport (not #app) so it isn't wiped out by the clear-and-rebuild renders in
   ui.js, and stays visible across every screen (login, list, detail). */
#version-footer {
  position: fixed;
  bottom: 0.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.6;
  pointer-events: none;
  z-index: 1;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(env(safe-area-inset-top, 0px) + 0.9rem) 1rem 0.9rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.6rem;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.15rem;
}

.app-title {
  flex: 1 1 auto;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-header {
  gap: 0.6rem;
}

.detail-heading {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.detail-heading .app-title {
  flex: 0 1 auto;
}

.btn-icon {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 0.6rem;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--border);
}

.btn-icon:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: 0.6rem;
  padding: 0.75rem 1.1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-primary:active {
  transform: translateY(1px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.field-input:focus {
  border-color: var(--accent);
}

/* ---------- Login screen ---------- */
.login-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--surface);
  border-radius: 1rem;
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.brand .brand-mark {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 1rem;
  font-size: 1.7rem;
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 700;
}

.brand-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-error {
  background: var(--negative-bg);
  color: var(--negative);
  border-radius: 0.6rem;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
}

/* ---------- Loading / error / empty states ---------- */
.loading-screen,
.error-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 60dvh;
  text-align: center;
}


.loading-text,
.error-text {
  color: var(--text-muted);
}

.error-text {
  color: var(--negative);
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem 1rem;
}

/* ---------- Avatars ---------- */
.avatar {
  flex: 0 0 auto;
  width: 3rem;
  height: 3rem;
  border-radius: 0.85rem;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
}

.avatar-0 { background: var(--avatar-0); }
.avatar-1 { background: var(--avatar-1); }
.avatar-2 { background: var(--avatar-2); }
.avatar-3 { background: var(--avatar-3); }
.avatar-4 { background: var(--avatar-4); }
.avatar-5 { background: var(--avatar-5); }
.avatar-6 { background: var(--avatar-6); }
.avatar-7 { background: var(--avatar-7); }

/* ---------- Games list ---------- */
.game-group + .game-group {
  margin-top: 1.75rem;
}

.group-title {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.game-card {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.85rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.game-card:hover {
  border-color: var(--accent);
}

.game-card:active {
  transform: translateY(1px);
}

.game-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.game-info-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.opponent-name {
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-meta-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.ruleset-name {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.game-lastmove,
.game-counts {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Badges / pills ---------- */
.score-badge {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.score-badge.large {
  font-size: 1.05rem;
  padding: 0.3rem 0.75rem;
}

.score-badge.positive {
  color: var(--positive);
  background: var(--positive-bg);
}

.score-badge.negative {
  color: var(--negative);
  background: var(--negative-bg);
}

.score-badge.neutral {
  color: var(--neutral);
  background: var(--neutral-bg);
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pill.your-turn {
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

@media (prefers-color-scheme: dark) {
  .status-pill.your-turn {
    color: var(--accent);
  }
}

.status-pill.their-turn {
  color: var(--text-muted);
  background: var(--surface-2);
}

.status-pill.finished {
  color: var(--text-muted);
  background: var(--surface-2);
}

.status-pill.ok {
  color: var(--positive);
  background: var(--positive-bg);
}

.status-pill.warning {
  color: var(--negative);
  background: var(--negative-bg);
}

.status-pill.neutral {
  color: var(--neutral);
  background: var(--neutral-bg);
}

/* ---------- Game detail ---------- */
.detail-screen {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.tile-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
}

.section-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: -0.4rem;
}

/* ---------- Tiles ---------- */
.rack-tiles {
  display: flex;
  flex-wrap: wrap;
  /* Matches .tile-grid's tile size/gap below (2.3rem/0.35rem) — at the previous 2.6rem/0.4rem,
     a full 7-tile rack (the max) still wrapped to 6-then-1 on common ~360px-wide phones. */
  gap: 0.35rem;
  padding: 0.75rem 0;
  background: var(--surface-2);
  border-radius: 0.85rem;
}

.tile-grid {
  display: grid;
  /* 2.3rem/0.35rem gap/0.7rem padding (down from 2.6/0.4/0.9) so one more tile fits per row on
     narrower phone screens — tile-letter's font-size below is trimmed to match. Left/right
     padding dropped entirely (top/bottom kept) so the grid gets the container's full width to
     fit more tiles per row on narrow phones. */
  grid-template-columns: repeat(auto-fill, minmax(2.3rem, 1fr));
  gap: 0.35rem;
  padding: 0.7rem 0;
  background: var(--surface-2);
  border-radius: 0.85rem;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 0.35rem;
  background: linear-gradient(155deg, var(--tile-from), var(--tile-to));
  border: 1px solid var(--tile-border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 2px 3px rgba(0, 0, 0, 0.15);
  color: var(--tile-text);
  display: grid;
  place-items: center;
}

.rack-tiles .tile {
  width: 2.3rem;
  height: 2.3rem;
  flex: 0 0 auto;
}

.tile-letter {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
}

.rack-tiles .tile-letter {
  font-size: 0.95rem;
}

.tile-grid .tile-letter {
  font-size: 0.95rem;
}

.tile-points {
  position: absolute;
  bottom: 0.15rem;
  right: 0.28rem;
  font-size: 0.6rem;
  font-weight: 700;
  opacity: 0.75;
  line-height: 1;
}

.tile-blank {
  background: linear-gradient(155deg, var(--tile-blank-from), var(--tile-blank-to));
  color: var(--tile-blank-text);
  border-style: dashed;
}

/* ---------- Proposed moves ---------- */
.move-list-wrap {
  margin-top: 0.4rem;
}

.move-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.move-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.move-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.move-tiles .tile {
  width: 2.1rem;
  height: 2.1rem;
  flex: 0 0 auto;
}

.move-tiles .tile-letter {
  font-size: 1rem;
}

.move-summary {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.move-words {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Plain content lists (e.g. bot/index.html) ---------- */
/* The global reset above (ul { list-style: none; ... }) suits the app's own custom-styled lists
   (game-list, move-list) but also strips bullets from ordinary prose lists — restore them here
   for any page's plain informational content. The :not([class]) half means a plain <ul> written
   in a content section just works, without having to remember the class: every list the reset is
   actually for carries a class of its own, so an unclassed one is prose by definition. */
.info-list,
.tile-section ul:not([class]) {
  list-style: disc;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* ---------- Plain content tables (e.g. bot/index.html's opponent bots) ---------- */
/* Scrolling lives on this wrapper, not the page: cells stay on one line (nowrap below) so columns
   line up down the table, which is the whole point of using one — a narrow phone scrolls the
   table sideways instead of the layout breaking. */
.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--text-muted);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Numeric columns: right-aligned and tabular so digits stack in columns and a row's numbers can
   be compared down the table at a glance. */
.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* A secondary line inside a cell (e.g. the live score under "Playing"). */
.data-table .sub {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.table-note {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
