:root {
  color-scheme: light;
  --cream: #f6f1e5;
  --ink: #244d3b;
  --mint: #9bddbf;
  --gold: #bd8c33;
  font-family:
    ui-rounded,
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--cream);
  color: var(--ink);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background:
    radial-gradient(ellipse at top right, #e4e7d283, transparent 45%),
    var(--cream);
}
button {
  font:
    700 13px ui-rounded,
    system-ui,
    sans-serif;
  min-height: 44px;
  padding: 7px 10px;
  color: var(--ink);
  background: #fffcf3;
  border: 1px solid #cbd0bf;
  border-radius: 24px;
  touch-action: manipulation;
  cursor: pointer;
}
button:disabled {
  background: #dedfd5;
  color: #7c8579;
  border-color: transparent;
  cursor: default;
}
button:focus-visible {
  outline: 3px solid #427ba5;
  outline-offset: 2px;
}
#app {
  max-width: 470px;
  margin: auto;
  padding: 8px 10px calc(28px + env(safe-area-inset-bottom, 0px));
  min-height: 100svh;
}
header {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 44px;
}
h1 {
  font-size: 15px;
  letter-spacing: 3px;
  flex: 1;
  margin: 0;
}
header button {
  padding: 6px 9px;
}
header #leaderboard {
  width: 44px;
  padding: 0;
}
h2 {
  font:
    700 28px Georgia,
    serif;
  margin: 2px 0;
}
.theme {
  text-align: center;
}
.theme #day {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.counters {
  display: flex;
  justify-content: space-around;
  border-block: 1px solid #ccd1be;
  margin: 4px 2px;
  padding: 2px;
}
.counters div {
  text-align: center;
}
.counters strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}
.counters small {
  font-size: 9px;
  letter-spacing: 1.5px;
}
#holders {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-height: 57px;
}
.holder {
  min-width: 0;
  text-align: center;
}
.holder button {
  width: 100%;
  height: 44px;
  min-width: 0;
  padding: 4px 2px;
  border-radius: 14px;
  font-size: 12px;
  position: relative;
}
.holder small {
  font-size: 9px;
  letter-spacing: 1px;
}
.holder.secret button {
  border-style: dashed;
}
.holder button.found {
  background: #eedca8;
  border: 1.5px solid var(--gold);
}
.badge {
  position: absolute;
  top: -5px;
  right: -3px;
  font-size: 10px;
  background: #d5ad52;
  border-radius: 50%;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
}
#cube {
  display: block;
  width: 200px;
  height: 116px;
  margin: 0 auto 2px;
  pointer-events: none;
}
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  gap: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}
#board .cell {
  min-height: 0;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #b4c3a6;
  position: relative;
  font-size: clamp(21px, 6.3vw, 29px);
  font-weight: 800;
  line-height: 1;
  overflow: hidden;
  background: var(--tile);
  touch-action: none;
  box-shadow:
    inset 0 1px 0 #fff8,
    0 1px 1px #48633720;
}
#board .shadow {
  background: #e3e7d8a0;
  border: 0;
  box-shadow: none;
}
#board .cell span {
  display: inline-block;
  pointer-events: none;
}
#board .cell small {
  position: absolute;
  font-size: 6px;
  top: 2px;
  left: 3px;
  font-weight: 700;
  pointer-events: none;
}
#board .cell.frozen {
  outline: 2px solid #c39943;
  outline-offset: -2px;
  background: #d7e2d6;
}
#board .cell.draft {
  background: #bddced;
  box-shadow: inset 0 0 0 3px #285a85;
}
#board .cell.chosen:not(.draft) {
  box-shadow: inset 0 0 0 3px #35634d;
}
#board .cell.moving {
  filter: brightness(1.07);
  outline: 2px solid #76a98b;
  outline-offset: -2px;
}
#joints {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
}
#status {
  min-height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  margin: 3px 0;
  line-height: 1.25;
}
#status.draft-status {
  font-size: 13px;
  font-weight: 750;
}
.theme-check {
  margin-inline-start: 0.4em;
  color: #276b41;
  font-weight: 800;
}
#status.error {
  color: #a34436;
}
.actions {
  display: grid;
  grid-template-columns: 1.65fr 1fr 1fr 1fr;
  gap: 6px;
}
.actions button {
  padding: 6px 2px;
}
.primary {
  background: var(--mint);
  border-color: transparent;
}
#lock {
  font-size: 10px;
  white-space: nowrap;
}
#lock[aria-pressed="true"] {
  background: #2e6549;
  color: #fff4cf;
}
#word-rail {
  display: flex;
  gap: 5px;
  overflow: auto;
  margin-top: 7px;
  scrollbar-width: thin;
}
#word-rail:empty {
  margin: 0;
}
#word-rail button {
  min-height: 32px;
  white-space: nowrap;
  font-size: 11px;
  border-left: 5px solid var(--word);
  padding: 4px 9px;
}
.quiet {
  display: block;
  min-height: 36px;
  font-size: 11px;
  margin: 3px auto 0;
  background: transparent;
  border: 0;
}
footer {
  text-align: center;
  font-size: 13px;
  margin: 0;
  color: #758c65;
}
footer span {
  font-size: 9px;
}
dialog {
  border: 1px solid #ccd0bd;
  border-radius: 20px;
  background: #fffcf3;
  color: var(--ink);
  width: min(94vw, 460px);
  max-height: 85dvh;
  padding: 16px;
  box-shadow: 0 12px 60px #17372840;
}
dialog::backdrop {
  background: #243a3060;
}
.panel-top {
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  background: #fffcf3;
  z-index: 2;
}
.panel-top h2 {
  font-size: 25px;
  flex: 1;
}
.panel-top button {
  font-size: 11px;
}
.menu-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.menu-list button {
  text-align: left;
  border-radius: 12px;
}
dialog p {
  font-size: 14px;
  line-height: 1.45;
}
.lesson {
  background: #edf0e1;
  border-radius: 14px;
  padding: 12px;
  margin: 10px 0;
}
.lesson strong {
  display: block;
}
.lesson .diagram {
  font-size: 28px;
  letter-spacing: 5px;
  text-align: center;
  margin: 8px;
}
table {
  width: 100%;
  font-size: 14px;
  border-collapse: collapse;
}
td,
th {
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid #dce0d0;
}
.result-score {
  font-size: 44px;
  text-align: center;
  margin: 12px;
}
.share-link {
  overflow-wrap: anywhere;
}
.hint-line {
  font-size: 12px;
  color: #627460;
}
.error {
  color: #a34436;
}
@media (max-height: 750px) {
  .theme h2 {
    font-size: 27px;
  }
  .counters {
    margin: 4px 2px;
  }
  .theme #day {
    font-size: 9px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  #app {
    max-width: 420px;
  }
  #cube {
    height: 70px;
    width: 126px;
  }
}

#net-motion {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}
.moving span {
  visibility: hidden;
}
.turning .draft-direction {
  visibility: hidden;
}
/* Qbist-sized board, light Foldword materials. Sound glyph is small; target is44px. */
#sound-toggle {
  width: 44px;
  min-width: 44px;
  padding: 11px;
  background: transparent;
  border-color: transparent;
}
#sound-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
header {
  gap: 3px;
}
h1 {
  font-size: 14px;
  letter-spacing: 2px;
}
header #share {
  padding-inline: 7px;
}
header #menu {
  padding-inline: 7px;
}
@media (max-width: 374px) {
  h1 {
    font-size: 12px;
    letter-spacing: 1px;
  }
  header button {
    font-size: 11px;
    padding-inline: 5px;
  }
}
#app {
  max-width: 460px;
  padding-inline: 6px;
}
#board {
  gap: 1px;
}
#board .cell {
  border-radius: 2px;
}
#board.locked-return {
  outline: 2px solid #c78d47;
  outline-offset: 2px;
}

/* v0.2.2: the playable surface fits the browser's actually visible viewport. */
#app { padding: 0 6px; min-height: 0; position: relative; isolation:isolate; --theme-motif:"🌱"; --theme-glow:#cdd8b5; }
#app[data-season="autumn"] { --theme-glow:#e6c693; }
#app[data-season="winter"] { --theme-glow:#bcd5df; }
#app::before, #app::after { content:var(--theme-motif); position:absolute; z-index:-1; pointer-events:none; font-size:170px; opacity:.055; }
#app::before { top:70px; left:-25px; transform:rotate(-25deg); }
#app::after { bottom:70px; right:0; transform:rotate(20deg); }
#game { height:var(--visible-height,100dvh); display:flex; flex-direction:column; align-items:stretch; padding:4px 0 8px; background:radial-gradient(ellipse at 90% 25%, color-mix(in srgb,var(--theme-glow) 24%,transparent),transparent 60%); }
#game header { flex:0 0 44px; }
.theme { height:40px; flex:0 0 40px; }
.theme h2 { font-size:27px; line-height:29px; margin:0; }
.theme #day { font-size:9px; line-height:11px; }
#holders { height:56px; min-height:56px; flex:0 0 56px; margin-top:3px; }
.holder small { display:block; line-height:12px; }
.cube-stage { display:grid; grid-template-columns:minmax(55px,1fr) minmax(0,240px) minmax(55px,1fr); align-items:center; height:var(--cube-height); flex:0 0 var(--cube-height); }
#cube { width:100%; height:100%; margin:0; object-fit:contain; }
.counter { text-align:center; }
.counter strong { display:block; font-size:27px; line-height:1.05; }
.counter small { font-size:9px; letter-spacing:1.5px; }
#board { width:var(--board-size); height:var(--board-size); flex:0 0 var(--board-size); align-self:center; }
#board .cell { font-size:clamp(15px,calc(var(--board-size) * .076),29px); }
#board .cell.frozen, #board .cell.draft { background:var(--tile); }
#board .cell.moving { background:#e9eadf; }
#status { height:25px; min-height:25px; flex:0 0 25px; margin:1px 0 2px; font-size:11px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.actions { flex:0 0 44px; margin-top:auto; }
.actions button { min-height:44px; }
footer { height:22px; line-height:22px; }
#word-rail { flex-wrap:wrap; overflow:visible; }
[hidden] { display:none !important; }

body { overflow-x:clip; }
#game { padding-bottom:max(8px,env(safe-area-inset-bottom,0px)); }

#board { max-width:100%; }
/* Decorative motifs must not enlarge Safari's layout viewport. */
#app { overflow:clip; }
#app::before { left:32px; font-size:140px; }
#app::after { right:40px; font-size:140px; }

.cube-stage { grid-template-rows:minmax(0,1fr); }
#cube { min-height:0; max-height:100%; }
#board { grid-template-rows:repeat(8,minmax(0,1fr)); }
#panel #finish { min-height:44px; width:100%; text-align:left; padding:10px; border:1px solid #ccd0bd; border-radius:12px; margin-top:12px; font-size:13px; }

/* Face guides remain uniform while letters slide through them. */
#board .cell.moving { background:var(--tile); }
/* v0.2.4: larger net, quieter tile edges, and visible theme decoration. */
.theme { height:36px; flex-basis:36px; }
.theme h2 { font-size:25px; line-height:26px; }
.theme #day { line-height:10px; }
#holders { height:44px; min-height:44px; flex-basis:44px; }
#status { height:22px; min-height:22px; flex-basis:22px; }
#board .cell.frozen { outline:none; }
#board .cell.moving { outline:none; filter:none; }
#board .cell:is(.draft, .chosen).moving { box-shadow:none; }
#cube { pointer-events:auto; touch-action:none; user-select:none; -webkit-user-select:none; -webkit-touch-callout:none; cursor:grab; }
#cube:active { cursor:grabbing; }
#cube:focus-visible { outline:2px solid #538caf; outline-offset:-2px; }
#app::before,#app::after { opacity:.105; }
#app::before { top:100px; left:12px; }
#app::after { bottom:56px; right:12px; }
.view-controls { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-top:10px; }
#board .cell.frozen { outline:0 solid transparent; }
#board .cell:focus-visible { outline:2px solid #427ba5; outline-offset:1px; }
.secret-caption { display:block; font-size:8px; line-height:10px; letter-spacing:.6px; text-transform:uppercase; }

/* Practice neutral cells are distinct from the colored cube faces. */
#board[data-workspace] .shadow {
  background: #e9dfc7;
  border: 1px solid #d5c7a5;
}
#board[data-workspace] .shadow.parked {
  background: #f7eac7;
  border-color: #aa8546;
}
#board[data-workspace] .vacant {
  border-style: dashed;
}

#board[data-flat-grid] {
  --grid-height: calc(var(--board-size) * .75 - .25px);
  grid-template-rows: repeat(6, minmax(0, 1fr));
  aspect-ratio: auto;
  height: var(--grid-height);
  flex-basis: var(--grid-height);
}
#board[data-flat-grid] .shadow {
  background: var(--tile);
  border: 1px solid #d5c7a5;
}

#board[data-flat-grid] .cell:not(.shadow) span { font-weight: 700; }
#board[data-flat-grid] .shadow span { font-weight: 400; }
#board[data-flat-grid] .cell.marked::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 24%;
  max-width: 11px;
  aspect-ratio: 1;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%235c584d' stroke-width='1.3' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath d='M2.82 9.18 9.18 2.82'/%3E%3C/svg%3E");
  pointer-events: none;
}
#board[data-flat-grid] .cell.moving.marked::after { visibility: hidden; }
#game[data-flat-grid] .actions {
  grid-template-columns: 1.45fr repeat(4, minmax(0, 1fr));
  gap: 5px;
}
#game[data-flat-grid] #lock { position: relative; }


#board[data-flat-grid] .cell.auto-dim > span { opacity: .42; }
#board[data-flat-grid] .cell.gold-star::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 33%;
  aspect-ratio: 1;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%23e9b640' stroke='%23785521' stroke-width='1.2' stroke-linejoin='round' d='M10 1 12.6 6.7 19 7.5 14.2 12 15.5 18.5 10 15.4 4.5 18.5 5.8 12 1 7.5 7.4 6.7Z'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* Keep the ignored-letter control at the upper-right edge of the grid. */
#game[data-flat-grid] #grid-tools {
  align-self: center;
  width: var(--board-size);
  height: 24px;
  flex: 0 0 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
#game[data-flat-grid] #hide-used {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: auto;
  min-width: 44px;
  height: 24px;
  min-height: 24px;
  padding: 1px 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  line-height: 1;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#game[data-flat-grid] #hide-used svg {
  width: 12px;
  height: 12px;
  flex: none;
}
#board[data-flat-grid][data-hide-used] .cell.marked > span,
#board[data-flat-grid][data-hide-used] .cell.marked::after {
  visibility: hidden;
}

/* Theme motif belongs entirely to the cube stage, never beneath the grid. */
#app[data-flat-grid]::before,
#app[data-flat-grid]::after { content: none; }
#game[data-flat-grid] .cube-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
#game[data-flat-grid] .cube-stage::before {
  content: var(--theme-motif);
  position: absolute;
  z-index: -1;
  left: 3%;
  top: 1%;
  font-size: min(135px, calc(var(--cube-height) * .84));
  opacity: .12;
  pointer-events: none;
  transform: rotate(-18deg);
}
