/* App layout and chess-specific components. */

/* ---------- shell: navigation rail (wide) / bottom bar (narrow) ---------- */
.shell { display: grid; grid-template-columns: 96px minmax(0, 1fr); min-height: 100dvh; }
.nav {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 16px 0; background: var(--md-sys-color-surface);
}
.nav-logo {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 24px; border-radius: var(--shape-lg);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  transition: border-radius var(--motion-spatial-fast);
}
.nav-logo:hover { border-radius: var(--shape-xl); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 8px 16px 8px 24px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--md-sys-color-surface);
}
.topbar h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { width: 48px; height: 48px; }
#page { width: 100%; max-width: 1440px; margin: 0 auto; padding: 8px 24px 40px; }

@media (max-width: 839px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; z-index: 20; inset: auto 0 0 0; height: auto; flex-direction: row; justify-content: space-around; gap: 0;
    padding: 12px 4px calc(12px + env(safe-area-inset-bottom)); background: var(--md-sys-color-surface-container);
  }
  .nav-logo { display: none; }
  .nav-item { flex: 1; }
  #page { padding: 4px 12px 112px; }
  .topbar { padding-inline-start: 16px; min-height: 56px; }
}

/* ---------- auth pages ---------- */
.page-auth { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; }
.auth { width: min(440px, 100%); }
.auth .brand { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.auth .brand .mark {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: var(--shape-xl);
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary);
  animation: brand-in var(--motion-spatial);
}
@keyframes brand-in { from { border-radius: 50%; transform: rotate(-30deg) scale(0.6); } }
.auth .card { padding: 24px; border-radius: var(--shape-xl); background: var(--md-sys-color-surface-container); --field-bg: var(--md-sys-color-surface-container); }
.auth form { display: grid; gap: 8px; }
.auth .links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.rules { list-style: none; padding: 4px 16px; margin: 0; display: grid; gap: 2px; }
.rules li { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--md-sys-color-on-surface-variant); }
.rules li.ok { color: var(--md-sys-color-primary); }
.rules .icon { width: 16px; height: 16px; }

/* ---------- lobby ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; align-items: start; }
@media (max-width: 839px) { .grid > .has-items { order: -1; } }
.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.tc {
  display: grid; justify-items: center; gap: 2px; padding: 12px 4px; border: none; cursor: pointer;
  border-radius: var(--shape-lg); background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface);
  transition: border-radius var(--motion-spatial-fast), background var(--motion-effects);
}
.tc b { font: 500 1.375rem/1.75rem var(--font-brand); }
.tc span { font-size: 0.75rem; color: var(--md-sys-color-on-surface-variant); }
.tc[aria-pressed="true"] { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border-radius: var(--shape-xl); }
.tc[aria-pressed="true"] span { color: inherit; opacity: 0.85; }
.empty { padding: 16px; text-align: center; color: var(--md-sys-color-on-surface-variant); }
.suggest { position: relative; }
.suggest ul { position: absolute; z-index: 10; inset-inline: 0; top: 100%; margin: 2px 0 0; padding: 4px; list-style: none; border-radius: var(--shape-sm); background: var(--md-sys-color-surface-container); box-shadow: var(--elev-2); }
.suggest li button { width: 100%; padding: 8px 12px; border: none; background: none; text-align: start; cursor: pointer; border-radius: var(--shape-xs); font: inherit; color: inherit; }
.suggest li button:hover { background: var(--md-sys-color-secondary-container); }

/* ---------- game ---------- */
.game { display: grid; grid-template-columns: minmax(280px, min(calc(100dvh - 220px), 880px)) minmax(300px, 400px); gap: 24px; justify-content: center; align-items: start; }
.board-col { width: 100%; display: grid; gap: 8px; }
.board-row { display: flex; gap: 8px; }
.board-area { position: relative; flex: 1; aspect-ratio: 1; min-width: 0; }
.board { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: var(--shape-sm); box-shadow: var(--elev-2); }
.board-area.myturn .board { box-shadow: 0 0 0 3px var(--md-sys-color-primary), var(--elev-2); }

.evalbar { position: relative; flex: none; width: 18px; border-radius: var(--shape-full); overflow: hidden; background: #3a3734; box-shadow: 0 0 0 1px var(--md-sys-color-outline-variant); }
.evalbar > i { position: absolute; inset-inline: 0; bottom: 0; height: 50%; background: #f2f0ec; transition: height 700ms var(--motion-spatial); }
.evalbar.flipped > i { bottom: auto; top: 0; }
.evalbar > b {
  position: absolute; inset-inline: 0; bottom: 4px; text-align: center; font: 700 0.5625rem/1 var(--font-plain); color: #3a3734;
  writing-mode: vertical-rl; transform: rotate(180deg);
}
.evalbar.black-ahead > b { bottom: auto; top: 4px; color: #f2f0ec; }

.player { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 6px 6px 8px; border-radius: var(--shape-lg); background: var(--md-sys-color-surface-container-low); }
.player .name { min-width: 0; }
.player .name a { color: inherit; text-decoration: none; font-weight: 500; }
.player .name small { display: block; color: var(--md-sys-color-on-surface-variant); font-size: 0.75rem; }
.clock {
  margin-inline-start: auto; min-width: 6.2ch; padding: 8px 14px; text-align: end;
  font: 500 1.75rem/1 var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
  border-radius: var(--shape-md); background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface);
  transition: background var(--motion-effects), border-radius var(--motion-spatial-fast);
}
.clock.running { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border-radius: var(--shape-xl); }
.clock.low.running { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }
.clock.flagged { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }

.side { display: grid; gap: 12px; }
.status { padding: 12px 16px; border-radius: var(--shape-lg); background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.status.result { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); border-radius: var(--shape-xl); }
.status.alert { background: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }
.moves {
  display: grid; grid-template-columns: 2.6em 1fr 1fr; align-content: start; max-height: 340px; min-height: 120px; overflow-y: auto;
  padding: 8px; border-radius: var(--shape-lg); background: var(--md-sys-color-surface-container-low);
  font-variant-numeric: tabular-nums;
}
.moves .no { padding: 4px 6px; color: var(--md-sys-color-on-surface-variant); font-size: 0.8125rem; }
.moves .mv { padding: 4px 8px; border: none; border-radius: var(--shape-sm); background: none; color: inherit; text-align: start; cursor: pointer; font: 500 0.9375rem/1.25rem var(--font-plain); }
.moves .mv:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.moves .mv.cur { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.toolbar .sep { flex: 1; }
.engine-line { font: 400 0.8125rem/1.25rem var(--font-mono); color: var(--md-sys-color-on-surface-variant); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 999px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .board-col { width: min(100%, max(320px, calc(100dvh - 56px - 220px))); justify-self: center; }
  .moves { grid-template-columns: repeat(auto-fill, minmax(4.2em, auto)); max-height: none; min-height: 0; display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
  .moves .no { flex: none; padding-inline: 4px 0; }
  .moves .mv { flex: none; }
}
@media (max-width: 599px) {
  .board-col { width: 100%; min-width: 0; }
  .clock { font-size: 1.5rem; }
  .player { min-height: 48px; }
}

/* ---------- profile / tournaments ---------- */
.ratings { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.rating { padding: 16px; border-radius: var(--shape-lg); background: var(--md-sys-color-surface-container); }
.rating b { display: block; font: 400 2rem/2.5rem var(--font-brand); }
.rating:first-child { border-radius: var(--shape-xl); background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.result-w { color: var(--md-sys-color-primary); font-weight: 600; }
.result-l { color: var(--md-sys-color-error); font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 48px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: var(--shape-full); cursor: pointer;
  transition: border-radius var(--motion-spatial-fast); outline-offset: 2px;
}
.swatch[aria-pressed="true"] { border-radius: var(--shape-md); border-color: var(--md-sys-color-on-surface); }
.board-swatch { display: grid; grid-template-columns: 1fr 1fr; width: 56px; height: 56px; overflow: hidden; }
.board-swatch i { display: block; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: var(--shape-md); width: max-content; }
.qr svg { width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 24px; font: 500 1rem/1.5rem var(--font-mono); }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 8px 0 16px; }
section.card + section.card { margin-top: 16px; }
