:root {
  --ink: #1c1a2b;
  --panel: #262338;
  --line: #3b3657;
  --text: #ece8f5;
  --muted: #a69fbf;
  --sq-light: #e9e3d6;
  --sq-dark: #8d80b4;
  --amber: #f0b23e;
  --bad: #ff8a73;
  --good: #8fd6a4;
  --board: min(calc(100dvh - 12.5rem), calc(100vw - 30rem));
  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 400 1rem/1.45 var(--font);
}

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

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 0.5rem;
  padding: 0.4rem 0.8rem;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.quiet { background: none; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.table {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--board) minmax(19rem, 25rem);
  gap: 2rem;
  justify-content: center;
  align-items: start;
  padding: 1.25rem;
}

/* Game column */

.play { width: var(--board); min-width: 0; }

.seat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 2.75rem;
}
.seat-name { font-weight: 500; }
#seat-elo { color: var(--muted); font-variant-numeric: tabular-nums; }
.seat-actions { display: flex; gap: 0.5rem; }
.status { color: var(--amber); text-align: right; }
.seat-bottom { justify-content: flex-start; }
.seat-actions { margin-left: auto; }
.verdict { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verdict.best { color: var(--good); }
.verdict.inaccuracy { color: var(--amber); }
.verdict.mistake, .verdict.blunder { color: var(--bad); }

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 0.375rem;
  overflow: hidden;
  box-shadow: 0 1.5rem 3rem -1rem #0009;
}
#board { width: 100%; height: 100%; }

cg-board {
  background: conic-gradient(var(--sq-dark) 90deg, var(--sq-light) 0 180deg, var(--sq-dark) 0 270deg, var(--sq-light) 0) 0 0 / 25% 25%;
}
cg-board square.last-move { background: rgb(240 178 62 / 0.4); }
cg-board square.selected { background: rgb(240 178 62 / 0.62); }
cg-board square.move-dest { background: radial-gradient(rgb(28 26 43 / 0.32) 20%, transparent 22%); }
cg-board square.move-dest.oc { background: radial-gradient(transparent 62%, rgb(28 26 43 / 0.32) 64%); }
cg-board square.move-dest:hover { background: rgb(240 178 62 / 0.45); }
cg-board square.check { background: radial-gradient(circle, rgb(255 80 60 / 0.9) 10%, rgb(255 80 60 / 0) 72%); }
.cg-wrap coords { font: 500 0.7rem var(--font); }
.cg-wrap coords.ranks { top: 0; left: 3px; }
.cg-wrap coords.ranks coord { transform: none; padding-top: 2px; }
.cg-wrap coords.files { left: 0; bottom: 0; height: auto; text-align: right; text-transform: none; }
.cg-wrap coords.files coord { padding: 0 3px 1px 0; }
.cg-wrap coords coord { color: var(--ink); opacity: 0.6; }

.promo {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  gap: 0.75rem;
  text-align: center;
  background: rgb(28 26 43 / 0.82);
}
.promo[hidden] { display: none; }
.promo p { margin: 0; font-weight: 500; }
.promo div { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }

.moves {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.9rem;
  max-height: 4.4rem;
  overflow-y: auto;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.moves li { white-space: nowrap; }
.moves .n { opacity: 0.6; margin-right: 0.3rem; }
.moves .mv { color: var(--text); margin-right: 0.3rem; }
.moves .mv.inaccuracy { color: var(--amber); }
.moves .mv.mistake, .moves .mv.blunder { color: var(--bad); }

/* Side column */

.side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: calc(100dvh - 2.5rem);
  min-height: 30rem;
}

.strength { padding: 0 0.25rem; }
.elo-read { display: flex; align-items: baseline; gap: 0.75rem; }
#elo-value {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.elo-tier { color: var(--muted); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.75rem;
  margin: 0.6rem 0 0;
  background: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 0.375rem;
  border-radius: 1rem;
  background: linear-gradient(90deg, var(--sq-dark), var(--amber));
}
input[type="range"]::-moz-range-track {
  height: 0.375rem;
  border-radius: 1rem;
  background: linear-gradient(90deg, var(--sq-dark), var(--amber));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.375rem;
  height: 1.375rem;
  margin-top: -0.5rem;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--text);
}
input[type="range"]::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--text);
}
.elo-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.colors {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  margin: 0.9rem 0 0;
  padding: 0;
}
.colors legend { float: left; margin-right: 0.5rem; padding: 0; color: var(--muted); }
.colors input { position: absolute; opacity: 0; }
.colors label span {
  display: block;
  padding: 0.25rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 2rem;
  cursor: pointer;
}
.colors input:checked + span { background: var(--text); color: var(--ink); border-color: var(--text); }
.colors input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }

.tutor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 0.875rem;
  padding: 0.9rem;
  gap: 0.6rem;
}
.tutor-head { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.tutor-set .step { display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.tutor-set .step button { padding: 0 0.5rem; line-height: 1.5; }

.log {
  position: relative;
  flex: 1;
  min-height: 6rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.25rem;
}
.msg { max-width: 92%; padding: 0.55rem 0.75rem; border-radius: 0.75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.from-tutor { align-self: flex-start; background: var(--ink); border-top-left-radius: 0.2rem; }
.msg.from-you { align-self: flex-end; background: var(--sq-dark); color: var(--ink); border-top-right-radius: 0.2rem; }
.msg.from-tutor span:empty::after { content: "…"; color: var(--muted); }
.log .old { opacity: 0.5; }
.note { color: var(--muted); font-size: 0.9rem; padding: 0.15rem 0.1rem; }
.note b { color: var(--text); font-weight: 500; }
.note.inaccuracy b { color: var(--amber); }
.note.mistake b, .note.blunder b, .note.error { color: var(--bad); }
.note.best b { color: var(--good); }
.note button { margin-left: 0.5rem; padding: 0.1rem 0.6rem; font-size: 0.85rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { border-radius: 2rem; padding: 0.2rem 0.75rem; font-size: 0.9rem; background: none; }
.chip[hidden] { display: none; }

.composer { display: flex; gap: 0.5rem; }
.composer input {
  flex: 1;
  min-width: 0;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.5rem 0.7rem;
}
.composer input::placeholder { color: var(--muted); }
.composer button { background: var(--amber); border-color: var(--amber); color: var(--ink); font-weight: 500; }

.tutor-set {
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
  padding: 0 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.tutor-set input { accent-color: var(--amber); }
.tutor-set select { font: inherit; color: inherit; background: var(--ink); border: 1px solid var(--line); border-radius: 0.4rem; padding: 0.1rem 0.3rem; }
#spend { font-variant-numeric: tabular-nums; }

.keyform { display: grid; gap: 0.4rem; padding: 0.75rem; border: 1px solid var(--line); border-radius: 0.75rem; }
.keyform[hidden], #forget[hidden] { display: none; }
.keyform label { font-weight: 500; }
.keyform:not([hidden]) ~ .chips, .keyform:not([hidden]) ~ #composer { display: none; }
.keyform p { margin: 0; color: var(--muted); font-size: 0.8rem; }
#forget { padding: 0 0.5rem; font-size: 0.8rem; }

.sheet-head, #open-settings, #newgame2, .backdrop, .status-mobile { display: none; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }

/* Phone and tablet in portrait: one screen without page scroll. The board is at the top, the chat with the
   tutor is directly below it, and the answer field is at the bottom. The settings are in a sheet. */
@media (max-width: 56rem) and (orientation: portrait) {
  :root { --board: min(100vw, calc(100dvh - 20rem), 36rem); }
  html, body { height: 100dvh; overflow: hidden; }
  body { touch-action: manipulation; }
  .table { display: flex; flex-direction: column; align-items: center; gap: 0; padding: env(safe-area-inset-top) 0 0; height: 100dvh; min-height: 0; }
  .play { flex: none; }
  .seat-top, .seat-bottom .seat-name, #newgame { display: none; }
  .status-mobile { display: inline; text-align: left; }
  .verdict:not(:empty) + .status-mobile { display: none; }
  #open-settings { display: inline-block; }
  .seat { width: 100vw; margin-left: calc((var(--board) - 100vw) / 2); padding-inline: 0.75rem; min-height: 2.75rem; }
  .board-frame { border-radius: 0; box-shadow: none; }
  .moves { display: none; }
  .side { flex: 1; min-height: 0; height: auto; width: min(100%, 36rem); gap: 0; }
  .tutor { background: none; border-radius: 0; padding: 0 0.75rem calc(0.6rem + env(safe-area-inset-bottom)); gap: 0.5rem; }
  .tutor-head { display: none; }
  .log { min-height: 0; }
  .msg { max-width: 100%; }
  .msg.from-tutor { background: var(--panel); }
  .chips { flex-wrap: nowrap; overflow-x: auto; flex: none; }
  .chip { white-space: nowrap; flex: none; }
  .settings {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    display: grid;
    gap: 1.25rem;
    max-height: 88dvh;
    overflow-y: auto;
    padding: 1rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
    background: var(--panel);
    border-radius: 1rem 1rem 0 0;
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  body.settings-open .settings { transform: none; visibility: visible; }
  body.settings-open .backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 0.6); }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; }
  .tutor-set { margin-top: 0; font-size: 0.95rem; }
  #newgame2 { display: block; }
  #elo-value { font-size: 3rem; }
}

/* Phone in landscape: the two columns of the desktop, with a smaller board. */
@media (max-width: 56rem) and (orientation: landscape) {
  :root { --board: min(calc(100dvh - 7.5rem), calc(100vw - 21rem)); }
  .table { grid-template-columns: var(--board) minmax(18rem, 1fr); gap: 1rem; padding: 0.5rem; }
  .side { height: auto; min-height: 0; }
  #elo-value { font-size: 2.5rem; }
}

@media (pointer: coarse) {
  button { min-height: 2.5rem; }
  .tutor-set .step button { min-width: 2.25rem; }
  .note button { min-height: 2rem; }
  input[type="range"] { height: 2.5rem; }
  input[type="range"]::-webkit-slider-thumb { width: 1.75rem; height: 1.75rem; margin-top: -0.7rem; }
  input[type="range"]::-moz-range-thumb { width: 1.4rem; height: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.msg ol { margin: 0.5rem 0 0; padding: 0.45rem 0 0 1.4rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; white-space: normal; }
.msg ol:empty { display: none; }
.msg ol b { color: var(--amber); font-weight: 500; }
