:root {
  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #20313a;
  --muted: #66757d;
  --paper: #fffdf7;
  --page: #f7f1e3;
  --blue: #2b6f89;
  --blue-dark: #1f5368;
  --blue-soft: #e9f5f8;
  --green: #397150;
  --green-soft: #e4f3e8;
  --red: #9b4033;
  --line: #d9d5c9;
  --card-back: #2b6f89;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--page); color: var(--ink); touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button { font: inherit; touch-action: manipulation; cursor: pointer; }

.memory-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.memory-header, .profile-summary, .setup-heading, .setup-actions, .practice-top, .finish-actions, .question-line, .question-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.memory-header { padding-right: 2px; padding-left: 2px; }
.activity-link { color: var(--blue-dark); font-size: 13px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
h1 { margin: 1px 0 0; font-size: clamp(27px, 3.3vw, 38px); line-height: 1.05; }
h2 { margin: 0; font-size: clamp(27px, 3.3vw, 38px); }
.profile-summary { flex: 0 0 auto; font-size: 16px; font-weight: 800; }
.quiet-button, .text-button { min-height: 44px; padding: 7px 13px; border: 2px solid #b8c6ca; border-radius: 12px; background: var(--paper); color: var(--blue-dark); font-weight: 800; }

.setup-card, .practice-card, .finish-card {
  min-height: 0;
  border: 3px solid white;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}

.setup-card { align-self: center; padding: clamp(18px, 2.6vw, 28px); }
.eyebrow { margin: 0 0 4px; color: var(--blue-dark); font-size: 13px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.save-note { max-width: 290px; margin: 0; color: var(--muted); font-weight: 700; text-align: right; }
.size-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 22px 0; }
.size-choice {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 7px;
  padding: 18px;
  border: 4px solid var(--line);
  border-radius: 21px;
  background: white;
  color: var(--ink);
}
.size-choice.is-selected { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.size-choice strong { font-size: 30px; }
.size-description { color: var(--muted); font-size: 15px; font-weight: 700; }
.size-choice small { min-height: 18px; color: var(--green); font-size: 13px; font-weight: 850; }
.mini-board { display: grid; width: 104px; height: 84px; gap: 5px; padding: 7px; border-radius: 14px; background: #dceef2; }
.mini-board i { border: 2px solid #fff; border-radius: 5px; background: var(--blue); box-shadow: 0 2px 0 var(--blue-dark); }
.mini-2x2 { grid-template-columns: repeat(2, 1fr); }
.mini-2x3 { grid-template-columns: repeat(3, 1fr); }
.mini-3x3 { grid-template-columns: repeat(3, 1fr); }
.setup-actions p { margin: 0; color: var(--muted); font-size: 18px; font-weight: 720; }

.primary-button, .secondary-button {
  min-width: 145px;
  min-height: 56px;
  padding: 9px 20px;
  border-radius: 15px;
  font-size: 20px;
  font-weight: 850;
}
.primary-button { border: 0; background: var(--blue); box-shadow: 0 3px 0 var(--blue-dark); color: white; }
.secondary-button { border: 3px solid var(--blue); background: white; color: var(--blue-dark); }
.primary-button:disabled, .hint-button:disabled { cursor: default; opacity: .42; box-shadow: none; }

.practice-tools { display: flex; flex: 0 0 auto; align-items: center; gap: 12px; }
.hint-button { min-width: 52px; min-height: 44px; padding: 7px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.hint-button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.practice-card { display: grid; grid-template-rows: auto minmax(0, 1fr); padding: 12px 16px 16px; }
.practice-top { min-height: 48px; border-bottom: 1px solid var(--line); }
.practice-top > strong { flex: 1; font-size: 19px; }
.memory-journey {
  --journey-position: 5%;
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  width: min(300px, 35vw);
  height: 38px;
  padding: 0 7px;
}
.memory-journey::before { position: absolute; right: 17px; left: 17px; height: 6px; border-radius: 99px; background: #cad4d7; content: ""; }
.journey-step { position: relative; z-index: 1; width: 18px; height: 18px; justify-self: center; border: 4px solid #91a5ab; border-radius: 50%; background: var(--paper); }
.journey-step.is-complete { border-color: var(--green); background: var(--green); }
.journey-finish { position: relative; z-index: 1; justify-self: center; font-size: 22px; }
.journey-traveler {
  position: absolute;
  z-index: 3;
  top: 1px;
  left: var(--journey-position);
  display: grid;
  place-items: center;
  width: 36px;
  height: 34px;
  border: 2px solid white;
  border-radius: 10px;
  background: #fff5cd;
  box-shadow: 0 2px 6px rgb(32 49 58 / 20%);
  font-size: 21px;
  transform: translateX(-50%);
  transition: left 450ms ease-in-out;
}
.practice-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); gap: clamp(15px, 2.5vw, 28px); min-height: 0; padding-top: 12px; }
.memory-board {
  display: grid;
  align-self: stretch;
  justify-self: center;
  width: min(100%, 660px);
  min-height: 0;
  gap: 12px;
  perspective: 1000px;
}
.memory-board[data-size="2x2"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); max-width: 570px; }
.memory-board[data-size="2x3"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); }
.memory-board[data-size="3x3"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, minmax(0, 1fr)); }
.memory-card { min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 18px; background: transparent; perspective: 900px; }
.memory-card:disabled { cursor: default; opacity: 1; }
.card-inner { position: relative; display: block; width: 100%; height: 100%; min-height: 0; border-radius: inherit; transform-style: preserve-3d; transition: transform 420ms ease-in-out; }
.memory-card.is-face-up .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  display: grid;
  inset: 0;
  place-items: center;
  overflow: hidden;
  border: 4px solid white;
  border-radius: inherit;
  backface-visibility: hidden;
  box-shadow: 0 4px 11px rgb(32 49 58 / 18%);
}
.card-back { background: linear-gradient(145deg, #3d8199, var(--card-back)); color: white; }
.card-back::before { width: 44%; aspect-ratio: 1; border: 5px solid rgb(255 255 255 / 78%); border-radius: 50%; content: "?"; font-size: clamp(30px, 5vw, 58px); font-weight: 900; line-height: 1.2; }
.card-front { background: #fffefa; transform: rotateY(180deg); }
.card-front svg { display: block; width: min(82%, 150px); height: min(82%, 150px); filter: drop-shadow(0 3px 2px rgb(32 49 58 / 14%)); }
.memory-card.is-wrong .card-face { border-color: #d56e5d; box-shadow: 0 0 0 6px rgb(213 110 93 / 26%); }
.memory-card.is-correct .card-face { border-color: #65a87b; box-shadow: 0 0 0 6px rgb(101 168 123 / 25%); }

.memory-controls { display: grid; min-height: 0; place-items: center; padding: 12px; border: 2px solid #d4e1e4; border-radius: 18px; background: #f8fcfd; }
.ready-panel, .study-panel, .question-panel { width: 100%; text-align: center; }
.ready-panel, .study-panel { display: grid; justify-items: center; gap: 13px; }
.ready-panel h2, .study-panel h2, .question-panel h2 { font-size: clamp(25px, 3vw, 34px); }
.ready-panel p, .study-panel p { margin: 0; color: var(--muted); font-size: 17px; font-weight: 700; }
.brain-icon { font-size: 62px; }
.study-timer { width: 100%; height: 20px; overflow: hidden; border: 3px solid #9db2b8; border-radius: 99px; background: white; }
.study-timer span { display: block; width: 100%; height: 100%; border-radius: inherit; background: #65a87b; transform: scaleX(1); transform-origin: left; }
.study-timer span.is-counting { transform: scaleX(0); transition: transform 10s linear; }
.question-line { justify-content: center; }
.question-line h2 { text-align: left; }
.audio-button { display: grid; flex: 0 0 auto; width: 52px; height: 50px; place-items: center; padding: 9px; border: 2px solid #9bb5be; border-radius: 14px; background: white; color: var(--blue-dark); }
.audio-button svg { width: 28px; height: 28px; fill: currentColor; }
.audio-button svg path:last-child { fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }
.memory-feedback { min-height: 34px; margin: 24px 0; color: var(--muted); font-size: 21px; font-weight: 800; }
.memory-feedback.is-wrong { color: var(--red); }
.memory-feedback.is-correct { color: var(--green); font-size: 25px; }
.question-actions { justify-content: center; }
.next-button { min-width: 120px; }

.finish-card { align-self: center; padding: 42px; text-align: center; }
.finish-card h2 { font-size: clamp(42px, 7vw, 70px); }
.finish-card > p:not(.eyebrow) { margin: 14px 0 26px; color: var(--muted); font-size: 23px; font-weight: 750; }
.finish-actions { justify-content: center; }

.rotate-message { display: none; position: fixed; z-index: 200; inset: 0; place-items: center; padding: 24px; background: var(--page); }
.rotate-card { display: grid; justify-items: center; gap: 12px; max-width: 430px; padding: 28px; border: 3px solid white; border-radius: 24px; background: var(--paper); box-shadow: 0 8px 24px rgb(69 67 57 / 15%); text-align: center; }
.rotate-icon { font-size: 55px; }
.rotate-card strong { font-size: 27px; }
.rotate-card span:last-child { color: var(--muted); }

@media (max-height: 700px) and (orientation: landscape) {
  .memory-shell { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .setup-card { padding: 15px 20px; }
  .size-picker { gap: 12px; margin: 10px 0; }
  .size-choice { min-height: 165px; padding: 10px; }
  .mini-board { width: 88px; height: 67px; }
  .practice-card { padding: 8px 13px 12px; }
  .practice-top { min-height: 42px; }
  .practice-layout { padding-top: 8px; }
  .memory-board { gap: 8px; }
  .memory-controls { padding: 8px; }
  .memory-feedback { margin: 13px 0; }
}

@media (max-width: 850px) and (orientation: landscape) {
  .practice-layout { grid-template-columns: minmax(0, 1fr) 245px; gap: 12px; }
  .memory-board { gap: 8px; }
  .memory-controls { padding: 8px; }
  .primary-button, .secondary-button { min-width: 120px; min-height: 50px; padding: 7px 13px; font-size: 18px; }
}

@media (orientation: portrait) and (max-width: 850px) {
  .memory-shell { display: none !important; }
  .rotate-message { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .journey-traveler, .study-timer span.is-counting { transition-duration: 1ms !important; }
}

.emet-motion-disabled .card-inner,
.emet-motion-disabled .journey-traveler { transition: none !important; }

.memory-page .task-floating-button {
  right: max(18px, env(safe-area-inset-right));
  left: auto;
}
