:root {
  --background: #F6F1E7;
  --card-back: #2E5C8A;
  --text: #222222;
  --right: #3C9D5D;
  --gold: #E8A317;
  --neutral: #B8B8B8;
  --button: #D9DBDA;
  --muted: #777777;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--background); color: var(--text); }
body { font-family: Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
#app {
  display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
}
nav { display: flex; gap: 8px; }
nav:empty { display: none; }
#menu { margin-bottom: 6px; }
#actions { margin-top: 10px; }
button {
  font: inherit; color: var(--text); background: var(--button); border: 0; border-radius: 4px;
  padding: 6px 8px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
button:active { filter: brightness(.92); }
button:disabled { cursor: default; }
nav button { flex: 1 1 0; min-height: 52px; font-size: clamp(14px, 3.6vw, 20px); font-weight: 500; }
#actions button { min-height: 60px; }
h1 { margin: 4px 0 0; text-align: center; font-size: clamp(22px, 6vw, 32px); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stars { text-align: center; color: var(--gold); font-size: clamp(24px, 7vw, 36px); letter-spacing: 2px; line-height: 1.3; min-height: 1.3em; white-space: nowrap; }
#subtitle { margin: 0 0 10px; text-align: center; font-size: clamp(18px, 4.6vw, 24px); min-height: 1.3em; }
#content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; position: relative; }
.center { margin: auto; text-align: center; font-size: 22px; max-width: 30em; }

/* Pictures and phrases */
.picture { flex: 1 1 0; min-height: 0; display: flex; justify-content: center; align-items: center; margin-bottom: 10px; container-type: size; }
/* The largest square that fits the space left. */
.picture img { width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); object-fit: cover; border: 3px solid var(--card-back); border-radius: 14px; background: #fff; }
.phrase {
  flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  background: #fff; border: 3px solid var(--card-back); border-radius: 14px; padding: 16px;
  font-size: clamp(24px, 7vw, 40px); line-height: 1.3; margin-bottom: 8px; overflow: auto;
}
.phrase b { color: var(--right); }
.hint { text-align: center; font-weight: 700; font-size: clamp(28px, 9vw, 44px); letter-spacing: .08em; white-space: nowrap; min-height: 1.4em; }
.hint.found { color: var(--right); letter-spacing: 0; }
.status { text-align: center; color: var(--muted); font-size: clamp(16px, 4.4vw, 21px); min-height: 2.6em; display: flex; align-items: center; justify-content: center; cursor: default; }
.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row > button { flex: 1 1 0; min-height: 60px; font-size: clamp(16px, 4.6vw, 22px); }
.choice { background: #fff; border: 3px solid var(--card-back); border-radius: 14px; box-shadow: none; font-size: clamp(18px, 5.4vw, 26px) !important; }
.choice.right { background: var(--right); border-color: var(--right); color: #fff; }
.choice.chosen { background: var(--neutral); border-color: var(--neutral); }
.choice.gone { visibility: hidden; }

/* Card and recall grids */
.grid { margin: auto; display: grid; gap: 8px; }
.card { position: relative; border-radius: 14px; overflow: hidden; cursor: pointer; perspective: 600px; }
.card .face { position: absolute; inset: 0; border-radius: inherit; display: flex; align-items: center; justify-content: center; transition: transform .3s; backface-visibility: hidden; }
.card .back { background: var(--card-back); color: #fff; font-weight: 700; }
.card .front { background: #fff; border: 3px solid var(--card-back); transform: rotateY(180deg); }
.card .front img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.card.open .back { transform: rotateY(180deg); }
.card.open .front { transform: rotateY(0); }
.card.matched { transition: opacity .4s, transform .4s; opacity: 0; transform: scale(.6); pointer-events: none; }
.card.empty { border: 3px solid var(--gold); color: var(--gold); display: flex; align-items: center; justify-content: center; cursor: default; }
.tile { position: relative; background: #fff; border: 3px solid var(--card-back); border-radius: 14px; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile span { font-weight: 700; padding: 0 6px; text-align: center; overflow: hidden; white-space: nowrap; }
.tile.found { border: 7px solid var(--right); }
.tile.found::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 38px; height: 38px; border-radius: 10px; background: var(--right); color: #fff; font-weight: 700; font-size: 24px; display: flex; align-items: center; justify-content: center; }
.tile.missed { border: 7px solid var(--right); }
.tile.wrong { opacity: .3; }
.study { flex: 1 1 0; min-height: 0; display: flex; }
.big-button { min-height: 64px; font-size: clamp(18px, 5vw, 24px); margin-top: 8px; }

/* Dialogs */
#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
#overlay[hidden] { display: none; }
.dialog { background: #fff; border-radius: 8px; max-width: 520px; width: 100%; max-height: 90dvh; overflow: auto; padding: 20px 22px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.dialog h2 { margin: 0 0 12px; font-size: 22px; }
.dialog p { font-size: 22px; margin: 0 0 12px; white-space: pre-line; }
.dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dialog .buttons button { background: none; box-shadow: none; color: var(--card-back); font-weight: 600; font-size: 19px; text-transform: none; padding: 10px 12px; }
.dialog label { display: flex; align-items: center; gap: 10px; font-size: 20px; padding: 7px 0; }
.dialog input[type=checkbox], .dialog input[type=radio] { width: 24px; height: 24px; }
.dialog .group { font-weight: 700; font-size: 19px; margin: 12px 0 4px; }
.dialog .radios { display: flex; flex-wrap: wrap; gap: 0 18px; }
.dialog input[type=number], .dialog input[type=text] { font: inherit; font-size: 22px; padding: 6px 8px; width: 140px; border: 1px solid #999; border-radius: 4px; }
.dialog input[type=text] { width: 100%; }
.dialog .note { font-size: 15px; color: var(--muted); }
.dialog .list { list-style: none; padding: 0; margin: 0; }
.dialog .list li { display: flex; align-items: center; gap: 12px; padding: 6px 0; font-size: 20px; }
.dialog .list img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.dialog .list button { margin-left: auto; }
.choice.game { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; }
.game-stars { color: var(--gold); font-weight: 700; white-space: nowrap; margin-left: 10px; }
.dialog .row button { font-size: 17px; }
.dialog p.about { font-size: 16px; margin: 0 0 6px; }
.about-list { font-size: 15px; padding-left: 20px; margin: 0; }
.phrase.question { font-size: clamp(22px, 6vw, 34px); }
.clock-box { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; margin-bottom: 10px; }
.clock-title { font-weight: 700; font-size: clamp(20px, 5.5vw, 28px); text-align: center; }
.clock { flex: 1 1 auto; min-height: 0; width: 100%; max-height: 60vh; }
.dialog input[type="text"] { width: 100%; font-size: 20px; padding: 6px; box-sizing: border-box; }
.dialog p.check { font-size: 17px; margin: 4px 0 8px; }
.dialog p.check.ok { color: var(--right); }
.dialog p.check.bad { color: #a33; }
.meter { height: 18px; border: 2px solid var(--card-back); border-radius: 9px; overflow: hidden; margin: 6px 0 10px; background: #fff; }
.meter .level { height: 100%; width: 0; background: var(--right); transition: width 60ms linear; }
