/* Inkwell: a calm, fixed paper-and-ink palette (the same in light and dark OS modes).
   One accent (ink blue) marks "your action"; gold marks points. */
:root {
  color-scheme: light;
  --bg: #efe9dd;
  --card: #fdfaf3;
  --paper: #fbf6ea;
  --ink: #232036;
  --muted: #6e6884;
  --soft: rgba(35, 32, 54, .07);
  --line: rgba(35, 32, 54, .14);
  --accent: #3a4e9a;
  --accent-soft: rgba(58, 78, 154, .14);
  --gold: #a5761f;
  --bad: #b23b32;
  --tile: #fffdf7;
  --radius: 14px;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #3a4e9a;
  --tut-accent-ink: #ffffff;
  --tut-bubble: #fdfaf3;
  --tut-ink: #232036;
  --tut-muted: #6e6884;
  --tut-dim: rgba(23, 20, 40, .55);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* Fill the screen: the page (written words) takes whatever is left over. */
@media (min-width: 0px) {
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
  .app { flex: 1 1 auto; min-height: 0; overflow: hidden; }
}

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 4px; flex: none;
  max-width: 1040px; width: 100%; margin: 0 auto; height: 50px;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
}
.back, .icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
  text-decoration: none; font-size: 22px; line-height: 1; cursor: pointer;
}
.back:hover, .icon-btn:hover { background: var(--soft); }
.brand {
  flex: 1; margin: 0; text-align: center; font-size: 18px; font-weight: 750;
  letter-spacing: .06em; font-variant: small-caps;
}
.back:focus-visible, .icon-btn:focus-visible, .btn:focus-visible, .pchip:focus-visible,
.tile:focus-visible, .entry:focus-visible, .seg button:focus-visible, .menu button:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------------- buttons */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0;
  background: var(--soft); cursor: pointer; font-weight: 650; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }
.btn.icon { min-width: 44px; padding: 0 12px; }
.btn .ico { font-size: 19px; line-height: 1; }
.btn .pts { font-variant-numeric: tabular-nums; opacity: .85; }

/* ------------------------------------------------------------- layout */
.app {
  max-width: 1040px; width: 100%; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 8px;
}
.side { display: grid; gap: 4px; align-content: start; min-width: 0; flex: none; }
.board-area { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1 1 auto; }
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; padding-top: 6px; }
  .board-area { grid-column: 1; grid-row: 1; height: calc(100vh - 74px); height: calc(100dvh - 74px); }
  .side { grid-column: 2; grid-row: 1; gap: 12px; }
}

/* ------------------------------------------------------------- score chips */
.rivals { display: flex; gap: 4px; flex-wrap: nowrap; min-width: 0; }
.pchip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 10px 0 5px; border: 0; border-radius: 20px;
  background: transparent; cursor: pointer; min-width: 0; flex: 0 1 auto;
  transition: background .2s, box-shadow .2s;
}
.pchip:hover { background: var(--soft); }
.pchip.turn { background: var(--card); box-shadow: 0 0 0 2px color-mix(in srgb, var(--pc) 45%, transparent), 0 1px 4px rgba(35, 32, 54, .08); }
.pchip.won .pts::after { content: " \2605"; color: var(--gold); }
.av {
  display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--pc, #888); color: #fff; font-size: 12px; font-weight: 800;
}
.pchip .nm { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .pts { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pchip.bump .av { animation: bump 1.1s ease-out 1 both; }
.pchip .delta {
  position: absolute; right: 0; top: -4px; font-size: 12px; font-weight: 800; color: var(--pc);
  animation: rise 1.2s ease-out 1 both; pointer-events: none;
}
@keyframes bump { 0% { box-shadow: 0 0 0 0 var(--pc); } 30% { box-shadow: 0 0 0 7px transparent; transform: scale(1.12); } 100% { box-shadow: none; transform: none; } }
@keyframes rise { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-9px); } }
@media (max-width: 599px) {
  .rivals[data-n="4"] .nm, .rivals[data-n="3"] .rival .nm { display: none; }
}

/* ------------------------------------------------------------- status */
.status {
  display: flex; align-items: center; gap: 8px; min-height: 24px;
  font-size: 15px; font-weight: 600; padding: 0 2px;
}
.status .dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--pc); }
.status.mine .dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.status.err .msg { color: var(--bad); }
.status.good .msg { color: var(--accent); }
.status.thinking .msg { color: var(--muted); }
.status.thinking .msg::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ------------------------------------------------------------- letter tiles */
.tile {
  position: relative; display: inline-grid; place-items: center; border: 0;
  width: var(--tsz, 40px); height: var(--tsz, 40px); border-radius: 9px;
  background: var(--tile); color: var(--ink);
  font-size: calc(var(--tsz, 40px) * .46); font-weight: 750; line-height: 1;
  text-transform: uppercase; cursor: default; padding: 0;
  box-shadow: 0 1px 2px rgba(35, 32, 54, .2), inset 0 -2px 0 rgba(35, 32, 54, .08);
  transition: transform .12s, box-shadow .12s, background .15s;
}
.tile .lv {
  position: absolute; right: 3px; bottom: 1px; font-size: 9px; font-weight: 700;
  color: var(--muted); line-height: 1;
}
.tile.vowel { background: #fff9ea; }
.tile.pick { cursor: pointer; }
.tile.pick:hover { transform: translateY(-2px); }
.tile.sel { box-shadow: 0 0 0 3px var(--accent), 0 5px 12px rgba(35, 32, 54, .22); transform: translateY(-3px); }
.tile.used { opacity: .32; }
.tile.fresh { animation: pop-in .5s ease-out 1 both; }
.tile.flash { animation: tflash 1.2s ease-out 1 both; }
@keyframes pop-in { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tflash { 0% { box-shadow: 0 0 0 5px var(--accent-soft), 0 0 0 3px var(--accent); transform: translateY(-4px); } 100% { box-shadow: 0 1px 2px rgba(35, 32, 54, .2); transform: none; } }

/* ------------------------------------------------------------- the inkwell */
.well-box { flex: none; }
.well {
  --tsz: clamp(34px, calc((100vw - 56px) / 9), 46px);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
  padding: 8px 8px 7px; border-radius: 16px;
  background: linear-gradient(180deg, #e3dccd 0%, #d9d1bf 100%);
  box-shadow: inset 0 2px 6px rgba(35, 32, 54, .13);
}
.well-note { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 3px; letter-spacing: .02em; }
@media (min-width: 900px) { .well { --tsz: 48px; } }

/* ------------------------------------------------------------- the page */
.page-box {
  flex: 1 1 auto; min-height: 56px; overflow: hidden;
  border-radius: 16px; background: var(--paper);
  background-image: repeating-linear-gradient(180deg, transparent 0 27px, rgba(58, 78, 154, .07) 27px 28px);
  box-shadow: inset 0 0 0 1px var(--line);
}
.page {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; padding: 8px;
}
.page.empty { align-content: center; justify-content: center; }
.page-hint { color: var(--muted); font-size: 13.5px; text-align: center; padding: 6px 14px; }
.entry {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 4px 10px 4px 8px; border: 0; border-radius: 11px;
  background: var(--card); box-shadow: 0 1px 3px rgba(35, 32, 54, .16), inset 0 0 0 2px transparent;
  font: inherit; text-align: left; cursor: default; transition: transform .12s, box-shadow .12s;
}
.entry .wd { font-size: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.entry .val { font-size: 13px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.entry .owner { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--pc); }
.entry .marks { font-size: 11px; color: var(--muted); }
.entry.mine { background: linear-gradient(180deg, #fdfaf3 0%, #f4f2fb 100%); }
.entry.pick { cursor: pointer; }
.entry.pick:hover { transform: translateY(-2px); }
.entry.sel { box-shadow: 0 0 0 3px var(--accent), 0 5px 12px rgba(35, 32, 54, .2); }
.entry.fresh { animation: pop-in .45s ease-out 1 both; }
.entry.taken { animation: tflash 1.3s ease-out 1 both; }

/* ------------------------------------------------------------- your side */
.my-side { flex: none; display: grid; gap: 6px; }
/* The tutorial kit's first-visit chip is fixed to the bottom centre: keep it off the rack. */
body:has(.tut-chip) .my-side { padding-bottom: 46px; }
.quill {
  display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap;
  min-height: 46px; padding: 4px 8px; border-radius: 13px;
  border: 2px dashed var(--line); background: rgba(255, 255, 255, .45);
}
.quill.has { border-style: solid; border-color: var(--accent-soft); background: var(--card); }
.quill .hint { color: var(--muted); font-size: 13px; }
.quill .tile { --tsz: 36px; }
.quill .tile.base { background: color-mix(in srgb, var(--pc) 16%, #fffdf7); box-shadow: 0 1px 2px rgba(35, 32, 54, .2), inset 0 0 0 1.5px var(--pc); }
.quill .verdict { font-size: 13px; font-weight: 700; padding: 0 6px; }
.quill .verdict.ok { color: var(--accent); }
.quill .verdict.no { color: var(--bad); }
.rack {
  --tsz: clamp(38px, calc((100vw - 60px) / 7), 52px);
  display: flex; justify-content: center; gap: 5px; min-height: 44px;
}
.actionbar {
  min-height: 52px; display: flex; gap: 6px; align-items: center; justify-content: center;
  padding: 0; white-space: nowrap;
}
.actionbar:empty { min-height: 8px; }

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(23, 20, 40, .42); padding: 14px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 420px; max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--card); border-radius: 20px; padding: 18px;
  box-shadow: 0 12px 40px rgba(20, 16, 40, .28);
  animation: pop .18s ease-out;
}
.modal.wide { max-width: 600px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 12px; font-size: 20px; text-align: center; }
.modal-head { display: flex; align-items: center; gap: 8px; margin: -6px -6px 8px 0; }
.modal-head h2 { flex: 1; margin: 0; text-align: left; }
.modal .lede { margin: -4px 0 14px; text-align: center; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { flex: 1 1 auto; }

/* menu */
.menu-overlay { background: rgba(23, 20, 40, .12); place-items: start end; padding: 50px 10px 0; }
.menu {
  min-width: 210px; background: var(--card); border-radius: 16px; padding: 6px;
  box-shadow: 0 10px 30px rgba(20, 16, 40, .22); animation: pop .15s ease-out; display: grid;
}
.menu button {
  min-height: 48px; padding: 0 14px; border: 0; background: transparent; text-align: left;
  border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 550;
}
.menu button:hover { background: var(--soft); }
@media (min-width: 1060px) { .menu-overlay { padding-right: calc((100vw - 1040px) / 2 + 8px); } }

/* setup */
.field { margin: 14px 0; }
.field-label { font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.field-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-weight: 650; }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

/* info */
.info-round { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.info-scores { display: grid; gap: 12px; }
.info-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.info-head .info-sub { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.info-head .total { margin-left: auto; font-size: 18px; }
.sub-title { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.wordlist { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.wchip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  background: var(--soft); font-size: 13px; white-space: nowrap; text-transform: uppercase; letter-spacing: .04em; font-weight: 650;
}
.wchip b { color: var(--gold); font-variant-numeric: tabular-nums; }
.wchip.muted { color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 13px; max-height: 38vh; overflow-y: auto; }
.log li { display: flex; gap: 7px; align-items: flex-start; }
.log li .av { width: 18px; height: 18px; font-size: 10px; margin-top: 1px; }
.log li.note { color: var(--muted); font-style: italic; }

/* help */
.help-body h3 { margin: 16px 0 4px; font-size: 15px; }
.help-body h3:first-child { margin-top: 0; }
.help-body p, .help-body li { font-size: 14px; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 4px 0; }

/* game over */
.go-table { display: grid; gap: 4px; }
.go-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; }
.go-row.win { background: var(--accent-soft); }
.go-row .place { width: 26px; color: var(--muted); font-size: 13px; font-weight: 700; }
.go-name { display: flex; flex-direction: column; font-weight: 700; min-width: 0; }
.go-name small { font-weight: 400; color: var(--muted); font-size: 12px; }
.go-row .total { margin-left: auto; font-size: 22px; font-variant-numeric: tabular-nums; }

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

/* Online play (online.js): a presence line under the status, in the same layout row. */
.status-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status-row .net { color: var(--muted); justify-content: flex-start; padding: 0 3px; }
body.is-online #btn-new { display: none; }
/* The online row sits above How to play and carries the menu's one divider. */
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
#over-leave { display: flex; width: 100%; margin-top: 8px; }
