:root {
  color-scheme: light;
  --paper: #f9edda;
  --ink: #351f1c;
  --quiet: #654139;
  --jam: #742437;
  --line: #bd8f6e;
  --green: #b7d99b;
  --amber: #ffce6c;
  --cream: #f6e4c1;
  --display: Georgia, 'Times New Roman', serif;
  --body: system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1rem/1.55 var(--body); }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--jam); text-underline-offset: .23em; }
a:hover { color: #431223; }
:focus-visible { outline: 3px solid #6d1736; outline-offset: 3px; }

.masthead {
  width: min(100% - 56px, 1710px);
  min-height: 70px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand img { display: block; flex: none; }
.brand h1, .brand span { margin: 0; font: bold clamp(1.75rem, 3vw, 2.45rem)/1 var(--display); letter-spacing: -.055em; }
.brand a { color: var(--ink); text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: clamp(5px, 2vw, 18px); }
.header-link { font-weight: 700; min-height: 44px; display: inline-flex; gap: .3em; align-items: center; white-space: nowrap; }
.language-switch { position: relative; z-index: 8; }
.language-switch summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 44px;
  min-height: 44px;
  list-style: none;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 750;
  color: var(--jam);
}
.language-switch summary::after {
  content: '';
  width: 5px;
  height: 5px;
  border: solid currentColor;
  border-width: 0 1px 1px 0;
  transform: translateY(-2px) rotate(45deg);
}
.language-switch summary::-webkit-details-marker { display: none; }
.language-switch summary:hover, .language-switch[open] summary { text-decoration: underline; }
.language-switch nav {
  position: absolute;
  inset: 100% 0 auto auto;
  min-width: 140px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff4de;
  box-shadow: 0 4px 12px #60281330;
}
.language-switch nav a { display: flex; align-items: center; min-height: 44px; padding: 0 12px; }
.language-switch [aria-current] { background: #f3e0c3; font-weight: 700; }
.footer a span { margin-inline-start: .3em; }
#guide h1 { font-size: clamp(1.9rem, 5vw, 3rem); overflow-wrap: anywhere; }
#game .button, .round-label { overflow-wrap: anywhere; }

#game {
  --board-height: min(77dvh, 850px);
  --board-width: min(100%, 1250px, calc(var(--board-height) * 1.49));
  position: relative;
  isolation: isolate;
  width: min(100% - 56px, 1710px);
  height: max(calc(100svh - 84px), calc(var(--board-height) + 52px));
  margin: 0 auto;
  padding: 18px clamp(22px, 2.4vw, 47px) 25px;
  overflow-anchor: none;
  display: grid;
  grid-template: minmax(0, 1fr) minmax(0, 1fr) / minmax(232px, .62fr) minmax(0, 2fr);
  grid-template-areas: 'heading board' 'tools board';
  column-gap: clamp(12px, 1.9vw, 38px);
  background:
    radial-gradient(ellipse at 63% 28%, #fff4d5 0%, #fff1d2b8 27%, #fff0cd00 70%),
    repeating-linear-gradient(124deg, #934b2610 0 1px, transparent 1px 5px),
    linear-gradient(142deg, #f8deae 16%, #f8dbab 60%, #edbc82);
  border: 1px solid #bb845a;
  border-radius: 30px;
  box-shadow: inset 0 1px #fff9e6, 0 8px 0 #e7c8a4, 0 11px 22px #60281317;
}
.game-heading { grid-area: heading; align-self: end; padding-bottom: 17px; }
.round-name { min-width: 0; }
#round-caption { min-height: 1.55em; margin: 0 0 2px; color: var(--quiet); font-weight: 650; font-size: .88rem; }
.round-label {
  margin: 0 0 11px;
  color: var(--jam);
  font: bold clamp(1.6rem, 3vw, 3.2rem)/1.07 var(--display);
  letter-spacing: -.045em;
}
.meters { display: flex; align-items: flex-start; gap: clamp(14px, 2vw, 28px); }
.meter { display: grid; justify-items: start; white-space: nowrap; }
.meter + .meter { border-left: 1px solid #b5825e; padding-left: clamp(14px, 2vw, 28px); }
.meter span { color: var(--quiet); font-weight: 650; }
.meter strong { font: bold clamp(1.85rem, 3.45vw, 3.4rem)/1 var(--display); font-variant-numeric: tabular-nums lining-nums; }
.meter:last-child strong { min-width: 3ch; }
.board-stage { grid-area: board; position: relative; min-width: 0; }
.board-mat {
  width: var(--board-width);
  height: var(--board-height);
  padding: clamp(6px, 1.1vw, 13px);
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  isolation: isolate;
  container-type: inline-size;
}
#game[data-mini="true"] .board-mat {
  width: min(var(--board-width), 365px);
  height: min(var(--board-height), 365px);
}
.tray {
  position: absolute;
  inset: 0;
  border: 2px solid #844023;
  border-radius: 17px;
  background:
    radial-gradient(ellipse at 15% 0, #f7bd67, transparent 54%),
    repeating-linear-gradient(135deg, #eb9a4921 0 2px, #7a2d120c 2px 6px),
    linear-gradient(145deg, #da8c45, #9f4b29);
  box-shadow: inset 0 2px 0 #ffda92, inset 0 -7px 0 #9c4b26, 0 8px 0 #7d3c25, 0 20px 26px #63331e4d;
}
#board {
  position: relative;
  display: grid;
  height: 100%;
  grid-template: repeat(5, minmax(0, 1fr)) / repeat(5, minmax(0, 1fr));
  gap: clamp(4px, 1.35cqw, 10px);
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#board[data-size="3"] { grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); gap: 7px; }
.well {
  border-radius: 13px;
  background: repeating-linear-gradient(45deg, #78381a0d 0 2px, #f8b65b14 2px 6px), #994b2b81;
  box-shadow: inset 0 3px 6px #602a18a3, inset 0 -1px #ffc174a3;
}
.tile {
  --face: var(--cream);
  --rim: #be9668;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 0 5%;
  border: 1px solid #6c3d26;
  border-radius: clamp(8px, 2.7cqw, 16px);
  background: linear-gradient(151deg, #fff4d051 4%, transparent 58%), var(--face);
  box-shadow: inset 0 2px #fff9dc96, inset 0 -5px var(--rim), 0 2px 2px #53261355;
  font: bold clamp(1.45rem, 9.5cqw, 4.55rem)/1 var(--display);
  touch-action: none;
  transition: filter 120ms, transform 110ms;
}
#board[data-size="3"] .tile { font-size: clamp(1.7rem, 15cqw, 4rem); }
.tile[data-mark="4"] { --face: var(--green); --rim: #78965d; color: #223b23; }
.tile[data-mark="1"], .tile[data-mark="2"], .tile[data-mark="3"] { --face: var(--amber); --rim: #c38a3e; }
.tile .tile-mark {
  position: absolute;
  bottom: 11%;
  inset-inline-end: 8%;
  font: 750 clamp(.64rem, 2.8cqw, 1.2rem)/1 var(--body);
}
.tile[aria-pressed="true"], .tile.is-drag-target {
  z-index: 2;
  outline: 3px solid var(--jam);
  outline-offset: 1px;
  transform: translateY(-4px);
  filter: brightness(1.1);
}
.tile:focus-visible { z-index: 2; outline-offset: -5px; }
.tile[data-lesson] { outline: 2px dashed #742437; outline-offset: -6px; }
.tile[data-lesson]:focus-visible { outline-style: solid; }
.tile[data-reviewed] { outline: 3px dashed var(--jam); outline-offset: -6px; }
.tile.is-flying { z-index: 4; }
.tile.is-source { transform: translateY(-3px); filter: brightness(1.1); }
.tile.axis-across::before, .tile.axis-down::after {
  content: '';
  position: absolute;
  background: #75263b;
  border-radius: 8px;
  pointer-events: none;
}
.tile.axis-across::before { inset: 9% 12% auto; height: 3px; }
.tile.axis-down::after { inset: 15% auto 13% 8%; width: 3px; }
@media (hover: hover) { #game:is([data-mode="playing"], [data-mode="tutorial"]) .tile:hover { filter: brightness(1.075); } }
.play-tools { grid-area: tools; align-self: start; min-width: 0; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 7px 13px; }
.legend li { display: flex; align-items: center; gap: 5px; font-size: .88rem; font-weight: 650; }
.chip {
  width: 23px;
  height: 23px;
  border-radius: 5px;
  border: 1px solid #865b3c;
  display: inline-grid;
  place-items: center;
  font: 750 .92rem/1 var(--body);
}
.exact { background: var(--green); }
.near { background: var(--amber); }
.far { background: var(--cream); }
#play-notes { min-height: 73px; padding-top: 6px; }
#status { max-width: 340px; margin: 2px 0; font-size: .96rem; color: #59382c; line-height: 1.4; }
#axis-details { margin: 0; color: var(--jam); font-weight: 750; line-height: 1.25; }
.tool-row, .button-row { display: flex; gap: 8px; }
.tool-row { min-height: 44px; flex-wrap: wrap; }
.button:disabled { opacity: .63; cursor: default; transform: none; }
#game[data-mini="true"] .meter { display: none; }
#game[data-mode="won"] :is(.legend, #play-notes), #game[data-mode="over"] :is(.legend, #play-notes) { display: none; }
#daily-notice { margin: 4px 0; color: var(--jam); font-size: .85rem; font-weight: 720; line-height: 1.25; }
.result-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; }
#result-details { margin: 4px 0 9px; color: var(--quiet); font-size: .92rem; }
.result-panel .button-row { flex-wrap: wrap; }
#daily-recap { display: flex; align-items: center; gap: 9px; margin: 14px 0 0; }
.daily-stamps { flex: none; display: grid; grid-template-columns: repeat(5, 14px); gap: 4px; }
.daily-stamps span {
  aspect-ratio: 1;
  border: 1px solid #95634b;
  border-radius: 3px;
  background: #fae5c4;
  box-shadow: inset 0 2px #c09976;
}
.daily-stamps [data-earned] {
  border-color: #835124;
  background: radial-gradient(circle, #9f591e 1px, transparent 1.4px) top left / 5px 5px #f4b65f;
  box-shadow: inset 0 -2px #ae632d;
}
#daily-goal { margin: 0; color: var(--quiet); font-size: .86rem; line-height: 1.28; }
#review-panel { margin-top: 9px; }
#review-step { margin: 0 0 5px; font-size: .9rem; font-weight: 720; }
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  transition: background-color 120ms, transform 120ms;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(2px); }
.primary { color: #fff8f1; background: var(--jam); border-color: #521a29; box-shadow: 0 3px #4e1927; }
.primary:hover { background: #8b2f48; }
.secondary { background: #f6e2bf; border-color: #af805b; }
.secondary:hover { background: #ffedc8; }
.subtle { background: #fbe8c5a6; border-color: #a57153; color: #5b292e; }
.subtle:hover { background: #fff3d5; }

.overlay {
  grid-area: board;
  position: relative;
  z-index: 6;
  display: grid;
  place-items: center;
  pointer-events: none;
  min-width: 0;
}
.panel {
  width: min(calc(100% - 16px), 356px);
  pointer-events: auto;
  padding: 22px 18px 24px;
  text-align: center;
  border: 1px solid #b08063;
  border-radius: 13px;
  background: #fff4de;
  box-shadow: 0 5px 0 #b37b57, 0 10px 24px #55231673, inset 0 0 0 4px #f7e4c7;
  animation: settle 180ms ease-out both;
}
.panel-title { margin: 0; color: #5f2331; font: bold clamp(1.7rem, 3.6vw, 2.85rem)/1.02 var(--display); letter-spacing: -.045em; }
.panel p:not(.panel-title):not(.record) { margin: 7px 0 13px; font-size: .94rem; color: var(--quiet); }
.panel .button-row { justify-content: center; flex-wrap: wrap; }
.panel .primary { padding-inline: 23px; }
.archive-line { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 10px; }
.archive-line .button { border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: .2em; }
#streak { color: var(--jam); font-size: .85rem; font-weight: 750; }
#archive-panel label { display: block; margin: 0 0 5px; font-size: .88rem; }
#archive-date { max-width: 100%; min-height: 44px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 8px; background: #fffaf1; color: var(--ink); font: inherit; }
.pause-actions { margin-top: 12px; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 12px; }
.options .button { font-size: .87rem; padding-inline: 7px; }
.options .button::before { content: '○'; font-size: 1rem; }
.options .button[aria-pressed="true"]::before { content: '✓'; }
.options .button[aria-pressed="true"] { background: #e3e7bd; }
.panel p.personal-best { margin: 10px 0 0; font-size: .86rem; }
.record { width: fit-content; margin: 0; border-radius: 30px; background: #f8d78e; color: #63293a; padding: 2px 10px; font-size: .82rem; font-weight: 750; }
#sparks { position: absolute; z-index: 5; inset: -8px; overflow: hidden; pointer-events: none; }
.spark {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 8px;
  height: 8px;
  background: var(--color);
  border: 1px solid #8e3d2c50;
  border-radius: 2px;
  animation: spark 720ms ease-out both;
}
.celebrate .board-mat { animation: toast 490ms ease-out; }
@keyframes settle { from { opacity: .65; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toast {
  0%, 12%, 100% { transform: none; }
  38% { transform: translateY(-7px) scale(1.018); filter: brightness(1.14); }
}
@keyframes spark {
  0%, 8% { opacity: 0; transform: translate(var(--start-x), var(--start-y)) scale(.35); }
  25%, 75% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--end-x), var(--end-y)) rotate(150deg); }
}

.story { max-width: 760px; padding: 0 24px; margin: 72px auto 62px; line-height: 1.7; }
.story h1, .story h2 { color: #582732; font-family: var(--display); line-height: 1.14; letter-spacing: -.024em; }
.story h1 { margin: 0 0 22px; font-size: clamp(2.4rem, 7vw, 4.4rem); }
.story h2 { margin: 35px 0 9px; font-size: clamp(1.55rem, 3.2vw, 2.15rem); }
.story p { margin: 0 0 14px; }
.story .article-intro { font-size: 1.14rem; }
.story ol { padding-left: 1.6em; }
.story li { padding-left: .2em; margin: 7px 0; }
.article-link { display: inline-block; font-weight: 750; }
.story details { border-bottom: 1px solid #cfa984; }
.story summary { color: #5e2938; min-height: 44px; padding: 10px 0; cursor: pointer; font-weight: 750; }
.story details p { padding-bottom: 6px; }
.story .independent { margin-top: 20px; color: var(--quiet); }
.guide-callout { margin-bottom: 14px; padding: 14px 18px; border-left: 4px solid #985535; background: #f5dfb9; border-radius: 0 6px 6px 0; }
.guide-callout p:last-child { margin-bottom: 0; }
.word { display: inline-block; letter-spacing: .16em; font-weight: 800; }
.footer {
  border-top: 1px solid #c5a081;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 25px;
  background: #f3e0c3;
}
.footer nav { display: flex; flex-wrap: wrap; gap: 0 19px; }
.footer a { display: inline-flex; min-height: 44px; align-items: center; font-weight: 650; }

@media (max-width: 740px), (max-width: 950px) and (orientation: portrait) {
  .masthead { width: calc(100% - 24px); min-height: 52px; gap: 5px; }
  .brand { gap: 7px; }
  .brand img { width: 30px; height: 30px; }
  .header-link { font-size: .88rem; }
  html[lang="en"] .masthead .brand span { font-size: clamp(1.35rem, 7.25vw, 1.75rem); }
  html:not([lang="en"]) .masthead .brand span { font-size: clamp(1.18rem, 5vw, 1.75rem); }
  html:not([lang="en"]) .header-link { font-size: .75rem; }
  #game {
    --board-width: min(100%, 680px);
    --board-height: clamp(270px, 63svh, 680px);
    width: calc(100% - 12px);
    min-height: calc(100svh - 60px);
    height: auto;
    padding: 7px 6px 12px;
    grid-template: auto auto 1fr / minmax(0, 1fr);
    grid-template-areas: 'heading' 'board' 'tools';
    gap: 7px;
    border-radius: 16px;
  }
  .game-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; align-self: auto; min-height: 44px; padding: 0 5px; }
  .round-label { margin: 0; font-size: 1.55rem; }
  html:not([lang="en"]) .round-label { font-size: clamp(1.25rem, 6vw, 1.55rem); }
  #round-caption { font-size: .73rem; margin-bottom: 0; }
  html[lang="pt"] #game[data-mini="false"] #round-caption:not(:empty) + .round-label { font-size: 1.15rem; }
  .meter { justify-items: center; }
  .meters { gap: 9px; }
  .meter + .meter { padding-left: 9px; }
  .meter span { font-size: .76rem; }
  .meter strong { font-size: 1.5rem; }
  .board-stage { height: var(--board-height); }
  .board-mat { inset-block-start: 0; translate: -50% 0; }
  .play-tools { text-align: center; padding: 8px 0 0; }
  .legend { justify-content: center; gap: 4px 11px; }
  .legend li { font-size: .82rem; }
  #play-notes { min-height: 49px; padding-top: 3px; }
  #status { margin: 2px auto; min-height: 0; font-size: .86rem; }
  #axis-details { font-size: .85rem; }
  .tool-row, .result-heading, .result-panel .button-row { justify-content: center; }
  #daily-recap { justify-content: center; }
  .tool-row .button, .result-panel .button { padding-inline: 11px; font-size: .88rem; }
  .result-heading .panel-title { font-size: 1.58rem; }
  #result-details { margin: 1px 0 6px; }
  #game[data-mini="true"] .board-mat { width: min(100%, 310px); height: min(84vw, 310px); }
  #game[data-mini="true"] .play-tools { translate: 0 calc(min(84vw, 310px) - var(--board-height)); }
  #game[data-mini="true"] .overlay { align-content: start; padding-top: 18px; }
  .panel { width: min(calc(100% - 18px), 320px); }
  .story { margin: 47px auto; padding: 0 20px; }
}

@media (min-width: 741px) and (max-width: 980px) {
  #game { width: calc(100% - 32px); padding: 20px; }
  .masthead { width: calc(100% - 38px); }
}

@media (max-width: 500px) and (max-height: 680px) and (orientation: portrait) {
  #game { --board-height: max(270px, 62svh); }
  .play-tools { padding-top: 6px; }
}

@media (min-width: 981px) and (min-height: 531px) {
  .menu-panel .panel-title { font-size: clamp(1.7rem, 3.3vw, 2.52rem); }
}

@media (orientation: landscape) and (max-height: 530px) and (min-width: 560px) {
  .masthead { width: calc(100% - 28px); min-height: 48px; }
  .brand img { width: 28px; height: 28px; }
  .brand h1 { font-size: 1.7rem; }
  #game {
    --board-height: max(252px, calc(100dvh - 80px));
    --game-height: max(298px, calc(100dvh - 63px));
    width: calc(100% - 20px);
    height: var(--game-height);
    min-height: 0;
    grid-template: minmax(0, 1fr) minmax(0, 1fr) / minmax(165px, .8fr) minmax(0, 1.2fr);
    grid-template-areas: 'heading board' 'tools board';
    gap: 0 13px;
    padding: 4px 16px 9px;
  }
  .game-heading { display: block; align-self: end; padding-bottom: 4px; }
  .round-label { margin-bottom: 4px; font-size: 1.55rem; }
  .meter strong { font-size: 1.7rem; }
  .meter span { font-size: .83rem; }
  .play-tools { display: block; min-height: 0; text-align: left; }
  .board-stage { height: auto; }
  .board-mat { inset-block-start: 50%; translate: -50% -50%; }
  #game:is([data-mode="won"], [data-mode="over"]) {
    height: auto;
    min-height: var(--game-height);
    grid-template-rows: auto minmax(min-content, 1fr);
  }
  #game:is([data-mode="won"], [data-mode="over"]) .board-stage {
    align-self: start;
    height: calc(var(--game-height) - 15px);
  }
  #game:is([data-mode="won"], [data-mode="over"]) .game-heading { align-self: start; padding-top: 6px; }
  .legend { justify-content: start; gap: 4px 9px; }
  #status { font-size: .84rem; margin: 2px 0; }
  .panel { padding-block: 14px 16px; }
  #game[data-mini="true"] .board-mat { width: min(100%, 280px); height: min(var(--board-height), 280px); }
}

@supports (padding: env(safe-area-inset-top)) {
  body { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
}

:root[data-motion="less"] *, :root[data-motion="less"] *::before, :root[data-motion="less"] *::after {
  animation-duration: .001ms !important;
  transition-duration: .001ms !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
