:root {
  --bg: #000;
  --panel: #16181c;
  --line: #2f3336;
  --text: #e7e9ea;
  --muted: #71767b;
  --blue: #1d9bf0;
  --bad: #f4212e;
  --good: #00ba7c;
  --like: #f91880;
  --radius: 16px;
  color-scheme: dark;
}

* { 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: 600px;
  min-height: 100dvh;
  margin: 0 auto;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- ヘッダー ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.home {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.home:hover { text-decoration: underline; }

.hud {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  visibility: hidden;
}
.hud.is-on { visibility: visible; }
.hud b { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; margin: 0 2px; }
.hud__time.is-low b { color: var(--bad); }
.hud__combo { transition: color .2s; }
.hud__combo.is-hot b { color: #ffd400; }

.timebar {
  height: 3px;
  background: var(--line);
}
.app:not(.is-playing) .timebar { visibility: hidden; }
.timebar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--blue);
  transform-origin: left;
  transform: scaleX(1);
}
.timebar i.is-low { background: var(--bad); }

/* ---------- 共通 ---------- */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 32px;
}

.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 28px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--text); color: #0f1419; }
.btn--primary:hover { background: #d7dbdc; }
.btn--ghost { background: transparent; color: var(--text); border-color: #536471; }
.btn--ghost:hover { background: rgba(231, 233, 234, .1); }

/* ---------- タイトル ---------- */
.screen--title { align-items: center; justify-content: center; gap: 22px; text-align: center; }

.logo {
  margin: 0;
  font-size: clamp(44px, 13vw, 72px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.02em;
}
.logo span { color: var(--blue); }

.howto {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 420px;
}
.howto__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
}
.howto__dir { font-size: 12px; color: var(--muted); }
.howto__item b { font-size: 22px; }
.howto__item small { font-size: 12px; color: var(--muted); }
.howto__item--bad b { color: var(--bad); }
.howto__item--good b { color: var(--good); }

.rules {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 1.7;
  color: #c4c8cb;
}
.rules b { color: var(--text); }
kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 0 .4em;
  border: 1px solid #536471;
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.6;
}

.best { margin: -8px 0 0; color: var(--muted); font-size: 14px; }
.best b { color: var(--text); }
.note { margin: 0; color: var(--muted); font-size: 12px; }

/* ---------- ポスト（X風） ---------- */
.tw {
  display: flex;
  gap: 12px;
}
.av {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  user-select: none;
}
.tw__body { flex: 1; min-width: 0; }
.tw__head {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
}
.tw__head b { overflow: hidden; text-overflow: ellipsis; }
.tw__head span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.tw__to { font-size: 14px; color: var(--muted); margin-top: 2px; }
.tw__to em { font-style: normal; color: var(--blue); }
.tw__text {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.tw__acts {
  display: flex;
  justify-content: space-between;
  max-width: 360px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
.tw__acts span { display: inline-flex; align-items: center; gap: 4px; }
.tw__acts svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- プレイ ---------- */
.screen--play { padding: 0; position: relative; }

.post {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  position: relative;
  transition: opacity .2s;
}
.post.is-swap { animation: swap .35s ease; }
@keyframes swap {
  0% { opacity: 0; transform: translateY(-6px); }
  100% { opacity: 1; transform: none; }
}
.post .tw__text { font-size: 17px; }

.replies-label {
  margin: 0;
  padding: 10px 16px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.deck {
  position: relative;
  flex: 1;
  min-height: 300px;
  margin: 10px 12px 0;
}

.deck__hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3em;
  opacity: .25;
  pointer-events: none;
  transition: opacity .15s;
}
.deck__hint--bad { left: -8px; color: var(--bad); }
.deck__hint--good { right: -8px; color: var(--good); }
.deck[data-lean="bad"] .deck__hint--bad,
.deck[data-lean="good"] .deck__hint--good { opacity: .9; }

.card {
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  padding: 16px 16px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .02);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  will-change: transform;
  transition: transform .25s cubic-bezier(.2, .8, .3, 1.2), opacity .25s;
}
.card:active { cursor: grabbing; }
.card.is-next {
  transform: translateY(14px) scale(.95);
  opacity: .45;
  pointer-events: none;
  z-index: 0;
}
.card.is-top { z-index: 2; }
.card.is-gone {
  pointer-events: none;
  z-index: 3;
  transition: transform .4s ease-in, opacity .4s ease-in;
}
.card .tw__text { font-size: 17px; }

.stamp {
  position: absolute;
  top: 18px;
  padding: 4px 12px;
  border: 4px solid currentColor;
  border-radius: 10px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: .04em;
  opacity: 0;
  pointer-events: none;
  background: rgba(0, 0, 0, .55);
  z-index: 1;
}
.stamp--bad { right: 16px; color: var(--bad); transform: rotate(12deg); }
.stamp--good { left: 16px; color: var(--good); transform: rotate(-12deg); }

.card.is-wrong { animation: shake .35s; }
@keyframes shake {
  20%, 60% { margin-left: -8px; }
  40%, 80% { margin-left: 8px; }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 18px;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom));
}
.ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
  height: 56px;
  justify-content: center;
  border-radius: 999px;
  border: 2px solid currentColor;
  background: transparent;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.ctl svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ctl:active { transform: scale(.94); }
.ctl--bad { color: var(--bad); }
.ctl--bad:hover { background: rgba(244, 33, 46, .12); }
.ctl--good { color: var(--good); }
.ctl--good:hover { background: rgba(0, 186, 124, .12); }
.ctl--good svg { fill: currentColor; stroke: none; }

.pop {
  position: absolute;
  left: 50%;
  top: 40%;
  z-index: 5;
  transform: translate(-50%, 0);
  font-weight: 900;
  font-size: 28px;
  pointer-events: none;
  animation: pop .8s ease-out forwards;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
}
.pop--good { color: #ffd400; }
.pop--bad { color: var(--bad); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50px) scale(1); }
}

.countdown {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .7);
  font-size: 120px;
  font-weight: 900;
}
.countdown span { animation: count .9s ease-out forwards; }
@keyframes count {
  0% { transform: scale(1.6); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.9); opacity: 0; }
}

.app.is-shake { animation: appshake .3s; }
@keyframes appshake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  z-index: 20;
  width: min(560px, calc(100% - 32px));
  transform: translate(-50%, 20px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast b { display: block; font-size: 15px; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { background: #b0141f; }

/* ---------- 結果 ---------- */
.screen--result { align-items: center; text-align: center; gap: 10px; }

.rank {
  margin: 8px 0 0;
  font-size: clamp(24px, 7vw, 36px);
  font-weight: 900;
  line-height: 1.3;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.rank-desc { margin: 0; color: #c4c8cb; font-size: 14px; line-height: 1.6; }

.final { margin: 8px 0 0; line-height: 1; }
.final b { font-size: 72px; font-weight: 900; font-variant-numeric: tabular-nums; }
.final span { font-size: 20px; margin-left: 4px; color: var(--muted); }

.newbest {
  margin: 0;
  color: #ffd400;
  font-weight: 800;
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 12px 0 4px;
}
.stats div {
  padding: 12px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 4px 0 0; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 8px;
}

.review-title {
  align-self: stretch;
  margin: 18px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 17px;
  text-align: left;
}
.review {
  align-self: stretch;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.review li {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.review__parent {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.review__reply { margin: 6px 0 8px; font-size: 15px; line-height: 1.55; }
.review__verdict {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.review__verdict.is-bad { background: rgba(244, 33, 46, .18); color: #ff6b75; }
.review__verdict.is-good { background: rgba(0, 186, 124, .18); color: #3ddca4; }
.review__why { margin: 8px 0 0; font-size: 13px; line-height: 1.6; color: #c4c8cb; }
.review-empty { color: var(--muted); font-size: 14px; }

@media (max-width: 420px) {
  .hud { gap: 10px; font-size: 12px; }
  .hud b { font-size: 15px; }
  .ctl { min-width: 0; flex: 1; }
}

@media (max-height: 680px) {
  .post .tw__text, .card .tw__text { font-size: 15px; }
  .post .tw__acts { display: none; }
  .deck { min-height: 240px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
