:root {
  --bg: #fff;
  --panel: #f4f6f9;
  --line: #e4e7ec;
  --text: #1f2430;
  --muted: #6b7380;
  --brand: #e5323b;
  --brand-soft: #fff0f0;
  --ok: #16a36a;
  --unread: #2f6bff;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

[hidden] { display: none !important; }

.app {
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ---------- ヘッダー ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.home { color: var(--muted); text-decoration: none; font-size: 14px; }
.home:hover { color: var(--text); }
.bar__logo { font-weight: 800; font-size: 15px; color: var(--brand); }

/* ---------- 画面共通 ---------- */
.screen { flex: 1; display: flex; flex-direction: column; padding: 20px 16px 32px; }

.kicker { margin: 8px 0 4px; color: var(--muted); font-size: 14px; text-align: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  border: 0;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
}
.btn--primary { background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(229, 50, 59, .28); }
.btn--primary:active { transform: translateY(1px); }
.btn--ghost { background: var(--panel); color: var(--text); }

/* ---------- タイトル ---------- */
.logo {
  margin: 4px 0 20px;
  text-align: center;
  font-size: clamp(26px, 7.4vw, 38px);
  line-height: 1.3;
  letter-spacing: .02em;
}
.logo span { color: var(--brand); }

.sample { margin: 0 0 16px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.rules { margin: 0 0 24px; padding: 0 0 0 1.2em; line-height: 1.8; font-size: 15px; }
.rules b { color: var(--brand); }

.screen--title .btn { align-self: center; min-width: 240px; }
.last { text-align: center; color: var(--muted); margin: 14px 0 0; }
.note { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* ---------- メール行 ---------- */
.mail {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.mail__dot { flex: none; width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--unread); }
.mail__body { flex: 1; min-width: 0; }
.mail__head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.mail__head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail__head time { flex: none; color: var(--muted); font-size: 12px; }
.mail__from { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail__subj { margin-top: 2px; font-size: 14px; font-weight: 700; line-height: 1.4; }
.mail__snip {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stamp {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%) rotate(-10deg);
  padding: 4px 10px;
  border: 3px solid var(--brand);
  border-radius: 6px;
  color: var(--brand);
  background: rgba(255, 255, 255, .85);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: .04em;
  pointer-events: none;
}
.mail--demo .stamp { animation: stampIn .5s .4s both cubic-bezier(.2, 1.6, .4, 1); }

/* ---------- プレイ ---------- */
.app.is-playing { height: 100dvh; }
.screen--play { padding: 0; position: relative; min-height: 0; }

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 10px 16px 8px;
  text-align: center;
}
.hud__item { display: flex; align-items: baseline; justify-content: center; gap: 4px; }
.hud__item small { color: var(--muted); font-size: 11px; }
.hud__item b { font-size: 22px; font-variant-numeric: tabular-nums; }
.hud__score b { color: var(--brand); }
.lives { color: var(--brand); letter-spacing: .1em; font-size: 16px !important; }

.timebar { height: 4px; background: var(--panel); }
.timebar i { display: block; height: 100%; width: 100%; background: var(--brand); transform-origin: left; }

.inbox-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.combo { color: var(--brand); }

.inbox {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  position: relative;
  flex: 1 1 0;
  min-height: 0;
}
.inbox .mail {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  animation: arrive .28s ease-out;
}
.inbox .mail:hover { background: #fafbfd; }
.inbox .mail:focus-visible { outline: 3px solid var(--unread); outline-offset: -3px; }

.mail.is-hit { background: var(--brand-soft); }
.mail.is-hit .stamp { animation: stampIn .35s both cubic-bezier(.2, 1.6, .4, 1); }
.mail.is-wrong { animation: shake .35s; background: #f3f4f6; }
.mail.is-wrong .stamp { border-color: var(--muted); color: var(--muted); animation: stampIn .35s both cubic-bezier(.2, 1.6, .4, 1); }
.mail.is-gone { animation: leave .3s forwards; pointer-events: none; }
.mail.is-done { pointer-events: none; }
.mail.is-done .mail__dot { background: transparent; }

.toast {
  position: absolute;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(31, 36, 48, .92);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { background: rgba(229, 50, 59, .95); }

/* ---------- 結果 ---------- */
.rank { margin: 4px 0 6px; text-align: center; font-size: clamp(26px, 7vw, 34px); font-weight: 900; color: var(--brand); }
.rank-desc { margin: 0 0 12px; text-align: center; color: var(--muted); line-height: 1.6; }
.final { margin: 0; text-align: center; font-size: 18px; }
.final b { font-size: 44px; font-variant-numeric: tabular-nums; }
.best-new { margin: 4px 0 0; text-align: center; color: var(--ok); font-weight: 700; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0;
}
.stats div { background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.result-actions .btn { flex: 1 1 180px; }

.sec-title { margin: 28px 0 10px; font-size: 16px; }

.review { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.review:empty { display: none; }
.review li { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.review li:last-child { border-bottom: 0; }
.review .tag { display: inline-block; margin-bottom: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.review .tag--miss { background: var(--brand-soft); color: var(--brand); }
.review .tag--wrong { background: #eef1f5; color: var(--muted); }
.review .r-subj { font-weight: 700; font-size: 14px; line-height: 1.45; }
.review .r-from { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }
.review .r-why { margin-top: 6px; font-size: 13px; line-height: 1.6; }
.perfect { margin: 0; color: var(--ok); font-weight: 700; }

.tips ul { margin: 0; padding: 14px 14px 14px 32px; background: var(--panel); border-radius: var(--radius); line-height: 1.7; font-size: 14px; }

/* ---------- アニメーション ---------- */
@keyframes arrive { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes leave { to { opacity: 0; transform: translateX(40px); } }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@keyframes stampIn {
  from { opacity: 0; transform: translateY(-50%) rotate(-10deg) scale(2.2); }
  to { opacity: 1; transform: translateY(-50%) rotate(-10deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
