/* Emoji Phrase — ticket-stub parlour game. System fonts and emoji only. */

:root {
  --bg: #f3ece1;
  --bg-spot: #f7d7bf;
  --ink: #1c1612;
  --muted: #6a5e54;
  --surface: #fffaf3;
  --surface-2: #f6efe5;
  --line: #e3d6c4;
  --accent: #d4522b;
  --accent-ink: #fffaf3;
  --accent-deep: #a63c1c;
  --teal: #24665d;
  --good: #1c7d59;
  --good-bg: #d6f0e3;
  --bad: #c13b32;
  --bad-bg: #fde3df;
  --key: #fffaf3;
  --key-ink: #1c1612;
  --key-edge: #d9cdb8;
  --key-hit: #1c7d59;
  --key-hit-ink: #fffaf3;
  --key-miss: #d9cdb8;
  --key-miss-ink: #6a5e54;
  --bulb-on: #f0bf46;
  --bulb-on-glow: #f7d98a;
  --bulb-off: #d4c6b3;
  --shadow: 0 18px 40px -22px rgba(70, 36, 16, 0.35);
  --focus: #1a5fb4;
  --radius: 18px;
  --tile-empty: #c3b195;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --sans: ui-rounded, "Segoe UI", system-ui, -apple-system, "Hiragino Sans", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14111a;
    --bg-spot: #3a241c;
    --ink: #f4eee6;
    --muted: #b8ae9f;
    --surface: #241f2c;
    --surface-2: #2c2734;
    --line: #3c3546;
    --accent: #ff7a45;
    --accent-ink: #2a1208;
    --accent-deep: #c85a2e;
    --teal: #7ec8bc;
    --good: #4ecb96;
    --good-bg: #1b3a2e;
    --bad: #ff7b70;
    --bad-bg: #3a1e1c;
    --key: #2c2734;
    --key-ink: #f4eee6;
    --key-edge: #40394b;
    --key-hit: #2a8f68;
    --key-hit-ink: #f4fff8;
    --key-miss: #3a3446;
    --key-miss-ink: #c9c0b4;
    --bulb-on: #ffd36a;
    --bulb-on-glow: #ffe29a;
    --bulb-off: #3a3444;
    --shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.55);
    --focus: #7cb4ff;
    --tile-empty: #6d6578;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 12% -10%, var(--bg-spot), transparent 55%),
    radial-gradient(700px 420px at 110% 8%, rgba(36, 102, 93, 0.12), transparent 50%),
    var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(0.4rem + var(--safe-t)) max(0.9rem, var(--safe-r)) calc(0.6rem + var(--safe-b)) max(0.9rem, var(--safe-l));
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(28, 22, 18, 0.06) 1px, transparent 1.2px);
  background-size: 18px 18px;
  opacity: 0.45;
}

@media (prefers-color-scheme: dark) {
  body::before {
    background-image: radial-gradient(rgba(244, 238, 230, 0.07) 1px, transparent 1.2px);
  }
}

img { display: block; max-width: 100%; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled { cursor: default; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 50;
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 8px;
}
.skip:focus { left: 0.6rem; top: 0.6rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.top, .mode-bar, .game, .countdown {
  width: 100%;
  max-width: 42rem;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.15rem 0 0.35rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.mark {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 8px;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.1;
}

.tag {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tools { display: flex; gap: 0.3rem; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
}

.icon-btn svg { fill: currentColor; }

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

@media (prefers-color-scheme: dark) {
  .icon-btn { box-shadow: none; }
  .icon-btn:hover { color: var(--accent); }
}

.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.2rem 0 0.7rem;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.segmented button {
  min-height: 36px;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  font-size: 0.9rem;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(28, 22, 18, 0.12);
}

.puzzle-no {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  position: relative;
}

.clue-card {
  position: relative;
  background:
    radial-gradient(circle at 0 12px, var(--bg) 7px, transparent 7.5px) 0 8px / 14px 20px repeat-y,
    radial-gradient(circle at 100% 12px, var(--bg) 7px, transparent 7.5px) 100% 8px / 14px 20px repeat-y,
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.5rem 1.15rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.cat {
  display: inline-block;
  margin: 0 0 0.45rem;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: 1px solid var(--line);
}

.emojis {
  margin: 0;
  font-size: clamp(2.1rem, 8vw, 3.25rem);
  line-height: 1.2;
  letter-spacing: 0.12em;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.lives {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.8rem 0 0.7rem;
  min-height: 22px;
}

.life {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bulb-on);
  box-shadow: 0 0 0 3px var(--bulb-on-glow), 0 0 10px var(--bulb-on);
  transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.life.off {
  background: var(--bulb-off);
  box-shadow: none;
  transform: scale(0.86);
}

.phrase {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 0.8rem 1.15rem;
  flex: 1 1 auto;
  min-height: 5.5rem;
  padding: 0.15rem 0 0.7rem;
}

.word {
  display: inline-flex;
  gap: 0.22rem;
  flex-wrap: nowrap;
}

.tile {
  display: inline-grid;
  place-items: center;
  min-width: 1.85rem;
  height: 2.35rem;
  padding: 0 0.12rem;
  border-radius: 6px;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
  text-transform: uppercase;
}

.tile.letter {
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.tile.letter.empty {
  background: var(--surface);
  border-color: var(--tile-empty, #c3b195);
}

.tile.letter.filled {
  border-color: var(--teal);
  background: var(--surface-2);
  color: var(--ink);
  animation: pop 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.tile.punct {
  border: 0;
  background: transparent;
  min-width: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.tile.space {
  width: 0.45rem;
  min-width: 0.45rem;
  height: 0;
  padding: 0;
  border: 0;
}

.tile.reveal-win {
  border-color: var(--good);
  background: var(--good-bg);
  color: var(--ink);
}

.tile.reveal-lose {
  border-color: var(--bad);
  background: var(--bad-bg);
  color: var(--ink);
}

@keyframes pop {
  0% { transform: scale(0.7); opacity: 0.2; }
  100% { transform: scale(1); opacity: 1; }
}

.keyboard {
  display: grid;
  gap: 0.35rem;
  margin-top: auto;
  padding-bottom: 0.15rem;
  user-select: none;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 0.28rem;
}

.key {
  flex: 1 1 0;
  max-width: 3.2rem;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--key-edge);
  border-radius: 8px;
  background: var(--key);
  color: var(--key-ink);
  font-weight: 750;
  font-size: 0.92rem;
  text-transform: uppercase;
  box-shadow: 0 2px 0 var(--key-edge);
  touch-action: manipulation;
}

.key:hover { filter: brightness(0.98); }
.key:active { transform: translateY(1px); box-shadow: none; }

.key.hit {
  background: var(--key-hit);
  color: var(--key-hit-ink);
  border-color: transparent;
  box-shadow: 0 2px 0 var(--accent-deep);
}

.key.miss {
  background: var(--key-miss);
  color: var(--key-miss-ink);
  border-color: transparent;
  box-shadow: none;
  opacity: 0.85;
}

.key:disabled { pointer-events: none; }

body.is-over .keyboard { display: none; }
body.is-over .game { justify-content: center; }
body.is-over .phrase { flex: 0 1 auto; padding-bottom: 0.9rem; }

.result {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.1rem 1.15rem;
  text-align: center;
  animation: rise 0.35s ease;
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.result-kicker {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--teal);
}

.result.lost .result-kicker { color: var(--bad); }

.result-title {
  margin: 0.15rem 0 0.35rem;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
}

.result-answer {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.result-misses {
  margin: 0.35rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.result-note {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn {
  min-height: 44px;
  padding: 0 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-weight: 700;
}

.btn:hover { border-color: var(--ink); }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 3px 0 var(--accent-deep);
}

.btn.primary:hover { filter: brightness(1.05); }
.btn.primary:active { transform: translateY(1px); box-shadow: none; }

.btn.wide { width: 100%; margin-top: 0.4rem; }

.countdown {
  margin: 0.55rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(0.8rem, var(--safe-t)) max(0.8rem, var(--safe-r)) max(0.8rem, var(--safe-b)) max(0.8rem, var(--safe-l));
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 22, 18, 0.45);
}

.modal-card:focus,
.modal-card:focus-visible { outline: none; }

.modal-card {
  position: relative;
  z-index: 1;
  width: min(28rem, 100%);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  background: var(--surface);
  color: var(--ink);
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.25rem 1.3rem;
}

.modal-card h2 {
  margin: 0 1.8rem 0.7rem 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.modal-card p { margin: 0 0 0.75rem; }

.modal-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  font-size: 1.4rem;
  line-height: 1;
}

.help-list {
  margin: 0 0 0.9rem;
  padding-left: 1.15rem;
}

.help-list li { margin: 0.3rem 0; }

.help-example {
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 0.8rem 0.7rem 0.7rem;
  text-align: center;
  margin: 0 0 0.9rem;
}

.help-example-label,
.help-cat,
.help-caption {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--muted);
}

.help-cat { color: var(--teal); margin-bottom: 0.4rem; }

.help-emojis {
  margin: 0.15rem 0 0.2rem;
  font-size: 2rem;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.help-tiles {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.22rem;
  margin: 0.15rem 0 0.45rem;
  flex-wrap: wrap;
}

.help-tiles .tile {
  min-width: 1.55rem;
  height: 2rem;
  font-size: 0.95rem;
}

.help-caption { letter-spacing: 0.04em; text-transform: none; font-weight: 500; }

.stat-row {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0 0 1.1rem;
  padding: 0;
  text-align: center;
}

.stat-row li { margin: 0; }

.stat-val {
  display: block;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-label {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.chart-title {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.chart { display: grid; gap: 0.28rem; }

.chart-row {
  display: grid;
  grid-template-columns: 1.4rem 1fr 1.6rem;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.bar-track {
  height: 18px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.bar {
  height: 100%;
  min-width: 0;
  width: 0;
  background: var(--teal);
  border-radius: 4px;
  color: var(--accent-ink);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 0.3rem;
  transition: width 0.45s ease;
}

.bar.fail { background: var(--bad); }
.bar.best { background: var(--accent); }
.bar.zero {
  background: transparent;
  color: var(--muted);
  justify-content: flex-start;
  padding: 0;
  width: 0;
  min-width: 0;
}

.stat-countdown {
  margin: 1.15rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-card textarea {
  width: 100%;
  resize: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  margin: 0 0 0.5rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-b));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--ink);
  color: var(--bg);
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.toast[hidden] { display: none; }

body.shake-lives .lives { animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@media (max-width: 420px) {
  .tile {
    min-width: 1.55rem;
    height: 2.1rem;
    font-size: 1rem;
  }
  .key { min-height: 44px; font-size: 0.85rem; }
  .emojis { letter-spacing: 0.08em; }
  .phrase { gap: 0.5rem 0.65rem; }
}

@media (max-height: 740px) {
  .emojis { font-size: clamp(1.8rem, 6vh, 2.6rem); }
  .clue-card { padding: 0.75rem 1.2rem 0.85rem; }
  .phrase { min-height: 4.4rem; padding-bottom: 0.4rem; }
  .tile { height: 2.05rem; min-width: 1.55rem; font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .life.off { transform: none; }
  body.shake-lives .lives { animation: none; }
}

.offscreen-copy {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}
