/* 白と濃紺を基調にした、経済誌のように読みやすい画面。 */
:root {
  --bg-dark: #ffffff;
  --bg-panel: #f4f7fa;
  --bg-card: #ffffff;
  --border-subtle: #d9e2eb;
  --border-active: #173f68;
  --color-up: #173f68;
  --color-up-glow: rgba(23, 63, 104, .12);
  --color-down: #a64049;
  --color-down-glow: rgba(166, 64, 73, .1);
  --color-gold: #87681e;
  --color-blue: #173f68;
  --text-main: #243647;
  --text-sub: #5e6e7e;
  --text-gold: #765b1b;
  --font-display: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Yu Gothic', Meiryo, sans-serif;
  --font-jp: 'Noto Sans JP', 'Yu Gothic', Meiryo, sans-serif;
  --font-heading: 'Yu Mincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  background: #f3f6f9;
  font-family: var(--font-display);
  line-height: 1.65;
}

button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible {
  outline: 3px solid #729ac3;
  outline-offset: 3px;
}

#app-wrapper {
  position: relative;
  width: 100%;
  max-width: 440px;
  height: 100%;
  max-height: 880px;
  background: var(--bg-dark);
  border: 1px solid var(--border-subtle);
  border-top: 5px solid var(--color-blue);
  border-radius: 5px;
  box-shadow: 0 12px 40px rgba(16, 47, 78, .08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (max-width: 480px) {
  #app-wrapper {
    max-width: 100%;
    max-height: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-top: 5px solid var(--color-blue);
    border-radius: 0;
  }
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

.screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  padding: 22px;
  opacity: 0;
  transition: opacity .2s ease;
  z-index: 10;
}
.screen.active { display: flex; opacity: 1; z-index: 20; }

/* タイトル */
#screen-title {
  align-items: center;
  text-align: center;
  overflow: auto;
  padding: 22px 24px 28px;
  gap: 18px;
}
#screen-title > * { flex-shrink: 0; }
.title-header { width: 100%; display: flex; justify-content: flex-end; gap: 8px; }
.btn-icon-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  background: #fff;
  color: var(--color-blue);
  font-size: .8rem;
}
.btn-icon-toggle:hover { background: var(--bg-panel); }
.title-main { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.game-logo-badge { font-size: .75rem; font-weight: 600; color: var(--text-sub); letter-spacing: .025em; }
.title-illustration { width: 150px; height: 64px; color: var(--color-blue); margin: 0 auto; }
.game-title {
  font-family: var(--font-heading);
  font-size: clamp(1.9rem, 8vw, 2.5rem);
  font-weight: 700;
  color: var(--color-blue);
  letter-spacing: -.04em;
  line-height: 1.4;
}
.game-subtitle { font-size: .8rem; line-height: 1.8; color: var(--text-sub); }
.high-score-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  width: 100%;
  font-size: .9rem;
  font-weight: 600;
  color: var(--color-blue);
}
.rule-guide-box {
  width: 100%;
  background: var(--bg-panel);
  border-radius: 4px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.rule-guide-row { display: flex; align-items: center; gap: 10px; text-align: left; }
.rule-icon { display: flex; justify-content: center; align-items: center; width: 30px; flex-shrink: 0; font-size: 1.5rem; }
.rule-text { min-width: 0; }
.rule-text strong { display: block; font-size: .8rem; font-weight: 600; color: var(--text-main); }
.rule-text small { display: block; font-size: .72rem; color: var(--text-sub); margin-top: 3px; }
.title-actions { width: 100%; margin-top: auto; padding-top: 2px; }
.title-footer { width: 100%; padding-top: 8px; border-top: 1px solid var(--border-subtle); font-size: .8rem; color: var(--text-sub); }
.title-footer a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 4px; font-weight: 600; color: var(--color-blue); text-decoration: underline; text-underline-offset: 3px; }
.title-footer a:hover { color: var(--text-sub); }
.btn-primary, .btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 13px 16px;
  border-radius: 4px;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.6;
  transition: background .15s ease, transform .15s ease;
}
.btn-primary { background: var(--color-blue); color: #fff; border: 1px solid var(--color-blue); }
.btn-primary:hover { background: #234f7c; }
.btn-primary:active, .btn-secondary:active { transform: scale(.98); }
.btn-secondary { background: #fff; border: 1px solid var(--border-subtle); color: var(--color-blue); }
.btn-secondary:hover { background: var(--bg-panel); }

/* 設定画面 */
#screen-settings { overflow-y: auto; gap: 20px; }
#screen-settings > * { flex-shrink: 0; }
.settings-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.settings-header h2 { font-size: 1.35rem; color: var(--color-blue); }
.settings-group { min-width: 0; border: 1px solid var(--border-subtle); border-radius: 4px; padding: 16px; }
.settings-group legend { padding: 0 6px; font-weight: 700; }
.settings-help { font-size: .78rem; color: var(--text-sub); line-height: 1.8; }
.settings-group .btn-secondary { margin-top: 12px; font-size: .85rem; min-height: 44px; }
.category-options { display: flex; flex-direction: column; margin-top: 10px; }
.settings-option { display: flex; align-items: center; gap: 10px; min-height: 48px; font-size: .85rem; cursor: pointer; }
.settings-option input { flex-shrink: 0; width: 20px; height: 20px; accent-color: var(--color-blue); }
.settings-option input:focus-visible { outline: 3px solid #729ac3; outline-offset: 3px; }
.settings-status { font-size: .78rem; color: var(--text-main); margin-top: 8px; min-height: 1.8em; }
.title-actions .settings-help { margin-bottom: 10px; }

/* カウントダウン */
#screen-countdown { justify-content: center; align-items: center; background: #fff; }
.countdown-num { font-size: 6rem; font-weight: 600; color: var(--color-blue); font-variant-numeric: tabular-nums; }
.go-text { font-size: 4.5rem; color: var(--color-blue); }
.countdown-preparing { font-size: 1.25rem; }

/* ゲーム画面。高さが足りなければ、カードを縮めず縦に送る。 */
#screen-game {
  justify-content: space-between;
  padding: 18px 22px 22px;
  overflow-x: hidden;
  overflow-y: auto;
}
.game-hud { display: flex; flex-direction: column; gap: 9px; width: 100%; flex-shrink: 0; z-index: 50; }
.game-masthead { font-family: var(--font-heading); color: var(--color-blue); font-size: 1.12rem; font-weight: 700; padding-bottom: 10px; margin-bottom: 2px; border-bottom: 1px solid var(--border-subtle); }
.hud-top-row { display: grid; grid-template-columns: 1.25fr 1fr .9fr; align-items: end; column-gap: 10px; }
.hud-badge { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 4px; font-weight: 600; color: var(--color-blue); font-variant-numeric: tabular-nums; line-height: 1.4; min-width: 0; }
.hud-label { flex-basis: 100%; color: var(--text-sub); font-size: .7rem; font-weight: 400; margin-bottom: 3px; white-space: nowrap; }
.hud-timer-badge { grid-column: 1; grid-row: 1; font-size: 1.7rem; }
.hud-score-badge { grid-column: 2; grid-row: 1; font-size: 1.18rem; justify-content: flex-end; text-align: right; overflow-wrap: anywhere; }
.hud-combo-badge { grid-column: 3; grid-row: 1; font-size: 1.18rem; justify-content: flex-end; text-align: right; }
.hud-unit { font-size: .75rem; font-weight: 400; }
.time-bar-track { width: 100%; height: 4px; background: #e9eef3; overflow: hidden; }
.time-bar-fill { height: 100%; width: 100%; background: var(--color-blue); transition: width .1s linear, background .3s; }
.time-bar-fill.urgent { background: var(--color-down); }
.fever-bar-container { display: flex; align-items: center; gap: 12px; }
.fever-label { font-size: .69rem; font-weight: 600; letter-spacing: .08em; color: var(--text-sub); }
.fever-bar-track { flex: 1; height: 4px; background: #e9eef3; overflow: hidden; }
.fever-bar-fill { height: 100%; width: 0; background: var(--color-blue); transition: width .2s ease; }
.fever-blazing { background: var(--color-gold); }
.card-arena {
  position: relative;
  flex: 1 0 420px;
  min-height: 420px;
  width: 100%;
  margin: 18px 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1000px;
}
.card {
  position: absolute;
  width: 100%;
  max-width: 396px;
  height: 100%;
  max-height: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--color-blue);
  border-radius: 3px;
  box-shadow: 0 4px 0 #edf2f6;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  user-select: none;
  cursor: grab;
  touch-action: pan-y;
  will-change: transform, opacity;
}
.card:active { cursor: grabbing; }
.card-next { transform: scale(.94); z-index: 10; opacity: .75; pointer-events: none; }
.card-current { z-index: 20; }
.stamp { position: absolute; top: 14px; padding: 5px 10px; border-radius: 4px; font-weight: 700; font-size: 1rem; text-align: center; pointer-events: none; opacity: 0; line-height: 1.3; z-index: 100; transition: opacity .05s ease; }
.stamp small { display: block; font-size: .7rem; }
.stamp-up { right: 14px; color: var(--color-blue); border: 2px solid var(--color-blue); transform: rotate(10deg); background: #eef4f9; }
.stamp-down { left: 14px; color: var(--color-down); border: 2px solid var(--color-down); transform: rotate(-10deg); background: #fff2f3; }
.card-header { display: flex; align-items: center; min-height: 34px; flex-shrink: 0; }
.card-category-badge { font-size: .78rem; font-weight: 600; color: var(--color-blue); line-height: 1.6; overflow-wrap: anywhere; }
.card-news-box { margin: 14px 0; }
.news-label { display: block; font-size: .69rem; color: var(--text-sub); letter-spacing: .1em; margin-bottom: 6px; }
.card-news-title { font-size: 1.22rem; font-weight: 700; line-height: 1.65; color: var(--text-main); overflow-wrap: anywhere; }
.card-divider { height: 1px; width: 100%; background: var(--border-subtle); margin: 4px 0 12px; flex-shrink: 0; }
.card-target-box { background: #eef4f9; border-radius: 3px; padding: 14px; }
.target-label { display: block; font-size: .72rem; color: var(--color-blue); margin-bottom: 6px; }
.card-target-text { font-size: 1.08rem; font-weight: 600; line-height: 1.65; color: var(--color-blue); overflow-wrap: anywhere; }
.card-swipe-hint { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .7rem; font-weight: 500; color: var(--text-sub); padding-top: 16px; flex-shrink: 0; }
.game-actions-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; z-index: 50; flex-shrink: 0; }
.btn-choice { min-height: 58px; padding: 11px 8px; border-radius: 4px; border: 1px solid var(--color-blue); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; transition: transform .1s, background .15s; }
.btn-choice:active { transform: scale(.97); }
.btn-down-style { background: #fff; color: var(--color-blue); }
.btn-down-style:hover { background: #eef4f9; }
.btn-up-style { background: var(--color-blue); color: #fff; }
.btn-up-style:hover { background: #234f7c; }
.btn-choice .choice-label { display: flex; flex-direction: column; align-items: center; font-size: .95rem; line-height: 1.4; }
.btn-choice small { font-size: .65rem; font-weight: 400; }
.btn-choice .choice-icon { font-size: 1.4rem; }

/* 結果と解説 */
#screen-result { overflow: auto; padding: 28px 24px; background: #fff; }
.result-content { display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%; }
.result-header { text-align: center; width: 100%; }
.result-badge-wrap { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin: 16px 0 12px; }
.result-rank-badge { font-size: 4rem; font-weight: 600; line-height: 1.2; color: var(--color-blue); }
.rank-ss, .rank-s { color: var(--color-gold); }
.rank-a, .rank-b, .rank-c { color: var(--color-blue); }
.new-record-pill { padding: 4px 9px; border-radius: 3px; background: #f7f0df; color: var(--text-gold); font-size: .7rem; font-weight: 600; }
.result-title-text { font-family: var(--font-heading); font-size: 1.25rem; font-weight: 700; color: var(--color-blue); overflow-wrap: anywhere; }
.economy-card { width: 100%; padding: 17px 12px; border-top: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); text-align: center; }
.economy-label { font-size: .75rem; color: var(--text-sub); }
.economy-value { font-size: 1.65rem; font-weight: 600; color: var(--color-blue); margin-top: 5px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.stat-box { min-width: 0; padding: 12px 14px; border-radius: 3px; background: var(--bg-panel); display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: .72rem; color: var(--text-sub); }
.stat-val { font-size: 1.25rem; font-weight: 600; color: var(--text-main); overflow-wrap: anywhere; }
.result-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.btn-share-x { background: #fff; color: var(--color-blue); border-color: var(--border-subtle); }
.btn-share-x:hover { background: var(--bg-panel); }
.review-wrapper { width: 100%; }
.btn-toggle-review { width: 100%; min-height: 44px; padding: 10px 4px; font-size: .8rem; font-weight: 600; line-height: 1.7; color: var(--color-blue); text-align: center; }
.review-section { display: none; width: 100%; margin-top: 12px; }
.review-list { display: flex; flex-direction: column; gap: 12px; }
.review-item { padding: 14px; border: 1px solid var(--border-subtle); border-left: 3px solid var(--color-up); border-radius: 3px; display: flex; flex-direction: column; gap: 10px; font-size: .82rem; }
.item-wrong { border-left-color: var(--color-down); background: #fffafb; }
.review-header { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.review-status { font-weight: 600; font-size: .75rem; }
.item-correct .review-status { color: var(--color-up); }
.item-wrong .review-status { color: var(--color-down); }
.review-news { font-weight: 600; color: var(--text-main); overflow-wrap: anywhere; }
.review-target { font-size: .85rem; color: var(--text-main); overflow-wrap: anywhere; }
.review-detail { padding-top: 10px; border-top: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: 10px; }
.review-ans-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: .75rem; color: var(--text-sub); }
.text-up { color: var(--color-up); }
.text-down { color: var(--color-down); }
.review-reason { font-size: .8rem; color: var(--text-main); line-height: 1.8; overflow-wrap: anywhere; }
.review-empty { text-align: center; color: var(--text-sub); font-size: .8rem; padding: 16px; }

@media (max-width: 360px) {
  #screen-title, #screen-result { padding-left: 16px; padding-right: 16px; }
  #screen-game { padding-left: 16px; padding-right: 16px; }
  .card { padding: 16px; }
  .card-news-title { font-size: 1.12rem; }
  .card-target-text { font-size: 1rem; }
  .card-swipe-hint { font-size: .65rem; gap: 4px; }
  .hud-label { font-size: .65rem; }
  .hud-top-row { column-gap: 6px; }
  .btn-choice { gap: 4px; }
}
