:root {
  --bg: #f4efe6;
  --ink: #1a2422;
  --muted: #5b6663;
  --card-back: #2a6b62;
  --card-front: #fff;
  --match: #e6f4f0;
  --accent: #2a6b62;
  --line: #d8d1c4;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  user-select: none;
}
.app {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(10px + var(--safe-t)) 14px calc(14px + var(--safe-b));
  position: relative;
}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  flex-wrap: wrap;
}
.bar h1, .bar .title {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  flex: 1 1 auto;
  text-align: center;
  line-height: 1.2;
}
.icon-btn, .text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn { display: grid; place-items: center; }
.icon-btn svg, .mute-icon { width: 24px; height: 24px; display: block; }
.icon-btn:active, .text-btn:active, .lang-btn:active, .level-btn:active, .card:active {
  background: rgba(26, 36, 34, 0.08);
}
.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}
.primary:disabled { opacity: 0.4; cursor: default; }
.lede {
  color: var(--muted);
  margin: 6px 0 14px;
  font-size: 0.95rem;
  line-height: 1.35;
}
.lang-row, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lang-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  flex: 1 1 calc(50% - 8px);
}
.lang-btn.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.block { margin-bottom: 22px; }
.level-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.level-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  text-align: left;
  min-height: 52px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}
.level-btn .num { font-weight: 750; color: var(--accent); min-width: 1.6em; }
.level-btn .meta { color: var(--muted); font-size: 0.82rem; }
.level-btn.is-done { border-color: var(--accent); }
.play {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 2px 0 8px;
  text-align: center;
}
.stats {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 6px;
}
.stats { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--ink); margin-bottom: 0; }
.best-line {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
  min-height: 1em;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.run-stats {
  display: flex;
  gap: 14px;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.run-stats .rec { color: #b8860b; }
.new-record {
  display: inline-block;
  background: #ffc400;
  color: #1a2422;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 14px;
  margin-bottom: 8px;
  animation: pulse 1.2s ease-in-out infinite;
}
.overlay .best-line { margin-bottom: 14px; font-size: 0.85rem; }
.rec-mini { display: block; font-size: 0.74rem; color: var(--accent); text-align: right; font-variant-numeric: tabular-nums; }
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.grid {
  width: min(100%, calc(100svh - 10.4rem));
  height: min(100%, calc(100svh - 10.4rem));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 7px;
}
.card {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  width: 100%;
  height: 100%;
  perspective: 700px;
  -webkit-perspective: 700px;
  cursor: pointer;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}
.card::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 10px;
  background: rgba(26, 36, 34, 0.05);
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none;
  z-index: 0;
}
.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
  -webkit-transition: -webkit-transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.card.is-up .card-inner {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}
.card.is-up:not(.is-gone) .front {
  box-shadow: 0 6px 14px rgba(26, 36, 34, 0.18);
}
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back {
  background: var(--card-back);
  color: #e9f4f1;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12);
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.08) 25%, transparent 25%),
    linear-gradient(225deg, rgba(255,255,255,0.08) 25%, transparent 25%),
    linear-gradient(45deg, rgba(255,255,255,0.08) 25%, transparent 25%),
    linear-gradient(315deg, rgba(255,255,255,0.08) 25%, transparent 25%);
  background-size: 14px 14px;
  background-position: 0 0, 7px 0, 7px -7px, 0 7px;
}
.back-mark {
  width: 28%;
  height: 28%;
  border: 2px solid rgba(255,255,255,0.55);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
}
.front {
  background: var(--card-front);
  border: 1px solid var(--line);
  transform: rotateY(180deg) translateZ(1px);
  -webkit-transform: rotateY(180deg) translateZ(1px);
  padding: 2px;
  overflow: hidden;
}
.card.is-match:not(.is-gone) .front {
  background: var(--match);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.card.is-hearing .front { box-shadow: 0 0 0 3px var(--accent); }
.card.is-gone {
  pointer-events: none;
  cursor: default;
}
.card.is-gone .card-inner {
  opacity: 0;
  transform: rotateY(180deg) scale(0.86);
  -webkit-transform: rotateY(180deg) scale(0.86);
  transition: transform 0.4s ease, opacity 0.4s ease;
  -webkit-transition: -webkit-transform 0.4s ease, opacity 0.4s ease;
}
.word {
  text-align: center;
  font-weight: 700;
  font-size: clamp(11px, 3.6vw, 17px);
  line-height: 1.15;
  padding: 3px;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.draw { width: 92%; height: 92%; display: block; }
.anim-bob { animation: bob 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 80%; }
.anim-sway { animation: sway 2.2s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
.anim-spin { animation: spin 8s linear infinite; transform-box: fill-box; transform-origin: 50% 50%; }
.anim-pulse { animation: pulse 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
.anim-float { animation: floaty 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes sway { 0%,100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(244, 239, 230, 0.88);
  padding: 20px;
  z-index: 6;
}
.overlay p { font-weight: 700; margin: 0 0 12px; font-size: 1.15rem; }
.linkish {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  min-height: 44px;
  cursor: pointer;
}
@media (prefers-reduced-motion: reduce) {
  .anim-bob, .anim-sway, .anim-spin, .anim-pulse, .anim-float { animation: none; }
  .card-inner, .card.is-gone .card-inner {
    transition: none;
    -webkit-transition: none;
  }
}

.share-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  margin-top: 10px;
  border: 1.5px solid var(--accent);
  background: #fff;
  color: var(--accent);
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.share-btn:active { background: var(--match); }
.home-tip {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(42, 107, 98, 0.08);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.home-tip strong { color: var(--ink); font-size: 0.86rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.overlay .actions { gap: 4px; }

/* ---- v7: 4x6 board, pause, new-word marker ---- */
.app.play { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.app.play .hint { font-size: 0.74rem; margin: 0 0 4px; line-height: 1.25; }
.app.play .stats { font-size: 0.84rem; }
.app.play .best-line { font-size: 0.72rem; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app.play .bar .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: 0.98rem; }
.app.play .bar { flex-wrap: nowrap; gap: 2px; }
.app.play .icon-btn { padding: 6px; }
.tag-new { color: #b8860b; font-weight: 700; }
.board-wrap { width: 100%; }
.app.play .grid {
  aspect-ratio: auto;
  max-width: none;
  max-height: none;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
}
.app.play .card::before { inset: 4px; }
.app.play .face, .app.play .card { border-radius: 10px; }
.app.play .word { font-size: calc(var(--cell, 80px) * var(--k, 0.18)); padding: 2px; overflow-wrap: normal; hyphens: manual; }
.app.play .draw { width: 94%; height: 94%; }
.new-dot {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: calc(var(--cell, 80px) * 0.15);
  line-height: 1;
  color: #e0a400;
  text-shadow: 0 0 2px #fff;
  pointer-events: none;
}
.pause-layer { background: var(--bg); z-index: 8; }
.pause-layer p { font-size: 1.4rem; }
.pause-actions { flex-direction: column; align-items: stretch; width: min(260px, 80%); gap: 8px; margin-top: 10px; }
.level-btn.is-next { border-color: #e0a400; box-shadow: 0 0 0 2px rgba(224, 164, 0, 0.35); }
.lv-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level-btn .meta { text-align: right; flex-shrink: 0; }
.level-btn.is-review { background: #fff8e6; border-style: dashed; }
.level-btn.is-review .lv-name { color: #8a6400; font-weight: 650; }

/* ---------- Mode chooser ---------- */
.mode-row { display: flex; flex-direction: column; gap: 10px; }
.mode-btn { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--accent); background: var(--accent); color: #fff; font: inherit; cursor: pointer; }
.mode-btn.mode-sent { background: #c2410c; border-color: #c2410c; }
.mode-btn:disabled { opacity: 0.4; cursor: default; }
.mode-ico { font-size: 1.9rem; line-height: 1; width: 36px; text-align: center; }
.mode-txt { display: flex; flex-direction: column; gap: 2px; }
.mode-txt strong { font-size: 1.15rem; }
.mode-txt small { font-size: 0.85rem; opacity: 0.9; }
/* ---------- Sentences ---------- */
.sent-top { display: flex; align-items: center; gap: 10px; margin: 6px 2px 4px; }
.timebar { flex: 1; height: 12px; border-radius: 6px; background: #e3dccf; overflow: hidden; }
.timebar-fill { height: 100%; width: 100%; background: var(--accent); transform-origin: left center; transition: transform 0.1s linear; }
.timebar-fill.is-low { background: #d9443b; }
.sent-clock { min-width: 34px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.sent-box { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 8px 2px 4px; }
.sent-text { font-size: 1.65rem; line-height: 1.35; font-weight: 650; text-align: center; color: var(--ink); }
.sent-text .blank { display: inline-block; min-width: 3.2em; border-bottom: 3px solid var(--accent); padding: 0 4px; line-height: 1.15; }
.sent-text .blank.is-ok { color: #1f8a4c; border-color: #1f8a4c; }
.sent-text .blank.is-bad { color: #1f8a4c; border-color: #d9443b; }
.sent-hint { font-size: 0.95rem; color: var(--muted); text-align: center; font-style: italic; }
.opts { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.opt { min-height: 60px; border-radius: 14px; border: 2px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: 1.3rem; font-weight: 650; cursor: pointer; box-shadow: 0 2px 0 rgba(0,0,0,0.08); }
.opt:active { transform: translateY(1px); }
.opt.is-ok { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }
.opt.is-bad { background: #d9443b; border-color: #d9443b; color: #fff; }
.opt.is-dim { opacity: 0.45; }
.big-score { font-size: 3.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.app.sent .overlay { background: rgba(244, 239, 230, 0.97); }
.hearts { text-align: center; font-size: 1.6rem; line-height: 1; letter-spacing: 6px; color: #d9443b; margin-top: 2px; }
.hearts .heart.is-empty { color: #c9bfb0; }
.hearts.is-hit { animation: heartHit 0.45s ease; }
@keyframes heartHit { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.sent-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 4px 0; }
.sent-prog, .sent-total { font-weight: 750; font-variant-numeric: tabular-nums; min-width: 64px; font-size: 1.05rem; }
.sent-total { text-align: right; }
.sent-status .hearts { margin: 0; }
.hearts-mini { color: #d9443b; letter-spacing: 2px; }
.level-btn.is-locked { opacity: 0.5; }
.sent-rules { text-align: center; font-size: 0.88rem; margin-top: 0; }
.reread-btn { align-self: center; display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 999px; border: 2px solid var(--accent); background: #fff; color: var(--accent); font: inherit; font-weight: 650; font-size: 0.95rem; cursor: pointer; }
.reread-btn:active { transform: translateY(1px); background: var(--match); }
.front .draw-fill, .app.play .front .draw-fill { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hard-dot { position: absolute; top: 2px; right: 4px; font-size: calc(var(--cell, 80px) * 0.17); line-height: 1; color: #8b2fd6; text-shadow: 0 0 2px #fff, 0 0 2px #fff; pointer-events: none; z-index: 2; }
.new-dot { z-index: 2; }
.tag-hard { color: #8b2fd6; font-weight: 700; }
.track-tabs { display: flex; gap: 6px; background: #e8e1d4; border-radius: 12px; padding: 4px; margin: 2px 0 10px; }
.track-tab { flex: 1; border: 0; border-radius: 9px; padding: 10px 6px; font: inherit; font-weight: 700; background: transparent; color: var(--muted); cursor: pointer; }
.track-tab.is-on { background: #fff; color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.level-btn .hard-mini { color: #8b2fd6; }
