/* 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. */

/* ---------- Theme tokens ---------- */
:root {
  --bg: #f7f3ea;
  --bg-frame: #e9e1cb;
  --surface: #ffffff;
  --surface-2: #f1ebdd;
  --text: #23261f;
  --text-muted: #6b6f60;
  --border: rgba(35, 38, 31, 0.12);

  --accent: #2f6f4f;
  --accent-strong: #1f5138;
  --accent-contrast: #f8f1de;

  --positive: #1f9d55;
  --positive-bg: rgba(31, 157, 85, 0.14);
  --negative: #c8483c;
  --negative-bg: rgba(200, 72, 60, 0.12);
  --neutral: #6b6f60;
  --neutral-bg: rgba(107, 111, 96, 0.12);

  --shadow-sm: 0 1px 2px rgba(35, 30, 15, 0.08);
  --shadow-md: 0 8px 24px rgba(35, 30, 15, 0.12);

  --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;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14170f;
    --bg-frame: #0b0d09;
    --surface: #1c2117;
    --surface-2: #242b1d;
    --text: #edf0e4;
    --text-muted: #a3a993;

    --border: rgba(255, 255, 255, 0.1);

    --accent: #6fc492;
    --accent-strong: #8fdcae;
    --accent-contrast: #0e2016;

    --positive: #4ad07f;
    --positive-bg: rgba(74, 208, 127, 0.16);
    --negative: #ff7b6e;
    --negative-bg: rgba(255, 123, 110, 0.16);
    --neutral: #a3a993;
    --neutral-bg: rgba(163, 169, 154, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.5);

    --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;

    color-scheme: dark;
  }
}

/* ---------- 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;
}

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;
}

/* ---------- Pull to refresh ---------- */
/* Fixed to the viewport (not #app) so it isn't wiped out by the clear-and-rebuild renders in
   ui.js. Height must match the PULL_THRESHOLD px baked into pull-to-refresh.js. */
.pull-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4rem;
  transform: translateY(-4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.pull-indicator.visible {
  opacity: 1;
}

.pull-indicator .spinner {
  width: 1.75rem;
  height: 1.75rem;
}

/* ---------- 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;
}

.refresh-button.spinning {
  animation: spin 0.8s linear infinite;
}

/* ---------- 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;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.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);
}

/* ---------- 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;
  gap: 0.4rem;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 0.85rem;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
  gap: 0.4rem;
  padding: 0.9rem;
  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.6rem;
  height: 2.6rem;
  flex: 0 0 auto;
}

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

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

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

.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);
}
