:root {
  --bg-table-top: #F7F1E4;
  --bg-table-bot: #E8D9BE;
  --indigo: #1E3A5F;
  --indigo-dark: #142842;
  --coral: #E85D4A;
  --coral-dark: #C74432;
  --gold: #E8A800;
  --cream: #FFFDF8;
  --ink: #2B2420;
  --muted: #76695C;
  --border: #DFD3BF;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic UI', system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 50% 35%, var(--bg-table-top) 0%, var(--bg-table-bot) 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* Subtle warm hinoki wood-grain / washi texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(139, 108, 66, 0.03) 0px,
      rgba(139, 108, 66, 0.03) 2px,
      transparent 2px,
      transparent 22px
    ),
    radial-gradient(rgba(30, 58, 95, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px;
  z-index: 0;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--safe-top) + 8px);
  padding-bottom: calc(var(--safe-bottom) + 10px);
  padding-left: 12px;
  padding-right: 12px;
}

/* HUD */
.hud {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-chip {
  background: rgba(255, 253, 248, 0.92);
  border: 2px solid var(--indigo);
  border-radius: 14px;
  padding: 5px 11px;
  display: flex;
  flex-direction: column;
  min-width: 90px;
  box-shadow: 0 3px 0 rgba(30, 58, 95, 0.16);
}

.hud-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.1;
}

.hud-value {
  font-size: 20px;
  font-weight: 900;
  color: var(--indigo);
  line-height: 1.15;
}

.hud-value.pop {
  animation: scorePop 0.22s cubic-bezier(0.2, 1.5, 0.5, 1);
}

@keyframes scorePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.22); color: var(--coral); }
  100% { transform: scale(1); }
}

.hud-timer-wrap {
  flex: 1;
  background: rgba(255, 253, 248, 0.92);
  border: 2px solid var(--indigo);
  border-radius: 14px;
  padding: 5px 10px 7px;
  box-shadow: 0 3px 0 rgba(30, 58, 95, 0.16);
}

.hud-timer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.plate-pill {
  font-size: 11px;
  font-weight: 900;
  color: var(--cream);
  background: var(--indigo);
  padding: 1px 8px;
  border-radius: 999px;
}

.hud-time {
  font-size: 19px;
  font-weight: 900;
  color: var(--indigo);
  line-height: 1;
}

.hud-time.urgent {
  color: var(--coral);
  animation: pulseUrgent 0.6s ease-in-out infinite;
}

@keyframes pulseUrgent {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.timer-track {
  width: 100%;
  height: 7px;
  background: #E7DFCF;
  border-radius: 999px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #3B82C4, #1E3A5F);
  border-radius: 999px;
  transition: width 0.1s linear;
}

.timer-fill.urgent {
  background: linear-gradient(90deg, #F59E0B, #E85D4A);
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 14px;
  border: 2px solid var(--indigo);
  background: rgba(255, 253, 248, 0.92);
  font-size: 19px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(30, 58, 95, 0.16);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(30, 58, 95, 0.16);
}

.hud-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 0 4px;
}

.remain-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.remain-label {
  font-size: 12px;
  font-weight: 900;
  color: var(--indigo);
}

.remain-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.remain-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--coral);
  border: 2px solid var(--indigo);
  transition: transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1), background 0.2s, opacity 0.2s;
}

.remain-dot.golden {
  background: #FFD028;
  box-shadow: 0 0 8px rgba(245, 184, 0, 0.8);
}

.remain-dot.found {
  background: transparent;
  border-color: rgba(30, 58, 95, 0.28);
  transform: scale(0.75);
}

.combo-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #FF7A45, #E85D4A);
  color: #FFF;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(232, 93, 74, 0.35);
  animation: comboPop 0.22s ease-out;
}

.combo-badge.fever {
  background: linear-gradient(135deg, #F5B800, #E85D4A);
  box-shadow: 0 0 14px rgba(245, 184, 0, 0.65);
}

.combo-mult {
  background: rgba(255, 255, 255, 0.25);
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
}

@keyframes comboPop {
  0% { transform: scale(0.7); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Main Stage */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

.toast-banner {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--indigo);
  color: #FFF;
  font-weight: 900;
  font-size: 16px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2.5px solid #FFF;
  box-shadow: 0 8px 20px rgba(20, 40, 66, 0.28);
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  animation: toastIn 0.3s cubic-bezier(0.2, 1.5, 0.5, 1);
}

.toast-banner.gold {
  background: linear-gradient(135deg, #F5B800, #E87D1E);
}

@keyframes toastIn {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(0.8); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* Bottom Controls */
.controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
  z-index: 5;
}

.recent-strip {
  flex: 1;
  height: 50px;
  background: rgba(255, 253, 248, 0.85);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.recent-empty {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.recent-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  animation: iconDrop 0.28s cubic-bezier(0.2, 1.5, 0.5, 1);
}

@keyframes iconDrop {
  0% { transform: scale(0.3) translateY(-12px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.shake-btn {
  position: relative;
  height: 50px;
  padding: 0 16px;
  border-radius: 16px;
  border: 2.5px solid var(--indigo);
  background: var(--cream);
  color: var(--indigo);
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 4px 0 var(--indigo);
  transition: transform 0.08s, box-shadow 0.08s;
  flex-shrink: 0;
}

.shake-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--indigo);
}

.shake-btn:disabled {
  opacity: 0.72;
  cursor: default;
}

.shake-btn-bg {
  position: absolute;
  inset: 0;
  background: rgba(30, 58, 95, 0.14);
  transform-origin: left center;
  transform: scaleX(0);
  pointer-events: none;
}

.shake-btn-content {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.shake-icon {
  font-size: 17px;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(27, 36, 48, 0.36);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.title-card,
.result-card,
.zukan-card {
  width: 100%;
  max-width: 400px;
  background: var(--cream);
  border: 3px solid var(--indigo);
  border-radius: 26px;
  padding: 22px 20px;
  box-shadow: 0 14px 36px rgba(20, 40, 66, 0.25), 0 6px 0 var(--indigo);
  animation: cardIn 0.28s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes cardIn {
  0% { opacity: 0; transform: translateY(16px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.title-card {
  text-align: center;
}

.title-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 900;
  color: var(--cream);
  background: var(--indigo);
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.title-logo {
  margin: 12px 0 8px;
  font-size: 36px;
  line-height: 1.12;
  font-weight: 900;
  color: var(--indigo);
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 rgba(232, 93, 74, 0.18);
}

.title-desc {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  font-weight: 700;
}

.title-desc strong {
  color: var(--coral);
}

.title-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.stat-pill {
  background: #F5EFE2;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.stat-val {
  font-size: 19px;
  font-weight: 900;
  color: var(--indigo);
}

.btn-primary {
  width: 100%;
  height: 54px;
  border-radius: 18px;
  border: 2.5px solid var(--indigo);
  background: linear-gradient(180deg, #F06D5B 0%, var(--coral) 100%);
  color: #FFF;
  font-family: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--indigo);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn-primary:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--indigo);
}

.btn-primary:disabled {
  background: #C7BFB1;
  cursor: wait;
}

.title-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.btn-secondary {
  flex: 1;
  height: 44px;
  border-radius: 14px;
  border: 2px solid var(--indigo);
  background: #FFF;
  color: var(--indigo);
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(30, 58, 95, 0.18);
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(30, 58, 95, 0.18);
}

.btn-icon-text {
  flex: 0 0 92px;
}

/* Result Card */
.result-card {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: center;
  padding: 18px 18px;
}

.result-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  color: var(--cream);
  background: var(--indigo);
  padding: 3px 12px;
  border-radius: 999px;
}

.rank-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 4px;
}

.rank-badge {
  font-size: 28px;
}

.rank-title {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  color: var(--indigo);
}

.rank-comment {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.result-score-box {
  background: #F5EFE2;
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 12px;
}

.new-record {
  display: inline-block;
  background: linear-gradient(135deg, #F5B800, #E85D4A);
  color: #FFF;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 10px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.result-score-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.result-score {
  font-size: 40px;
  font-weight: 900;
  color: var(--coral);
  line-height: 1.1;
  margin-bottom: 8px;
}

.result-mini-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  border-top: 1.5px dashed var(--border);
  padding-top: 8px;
}

.result-mini-stats div {
  display: flex;
  flex-direction: column;
}

.result-mini-stats span {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.result-mini-stats strong {
  font-size: 15px;
  font-weight: 900;
  color: var(--indigo);
}

.result-caught-section {
  text-align: left;
  margin-bottom: 14px;
}

.result-section-title {
  font-size: 12px;
  font-weight: 900;
  color: var(--indigo);
  margin-bottom: 6px;
}

.result-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 128px;
  overflow-y: auto;
  padding: 6px;
  background: #FAF6EE;
  border: 1.5px solid var(--border);
  border-radius: 14px;
}

.caught-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFF;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 3px 8px 3px 4px;
  font-size: 12px;
  font-weight: 900;
  color: var(--indigo);
}

.caught-pill img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.caught-pill .new-tag {
  background: var(--coral);
  color: #FFF;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 6px;
  margin-left: 2px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-sub-actions {
  display: flex;
  gap: 10px;
}

/* Zukan Modal */
.zukan-card {
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.zukan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.zukan-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  color: var(--indigo);
}

.zukan-progress {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 2px solid var(--indigo);
  background: #FFF;
  color: var(--indigo);
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.zukan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 10px;
}

.zukan-item {
  background: #FAF6EE;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.zukan-item.selected {
  border-color: var(--coral);
  background: #FFF6F3;
}

.zukan-item img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.zukan-item-name {
  font-size: 11px;
  font-weight: 900;
  color: var(--indigo);
  text-align: center;
  line-height: 1.2;
}

.zukan-item.locked .zukan-item-name {
  color: var(--muted);
}

.zukan-item-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.zukan-detail {
  background: #F5EFE2;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.zukan-detail-empty {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.zukan-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.zukan-detail-name {
  font-size: 15px;
  font-weight: 900;
  color: var(--indigo);
}

.zukan-detail-stars {
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 1px;
}

.zukan-detail-trivia {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink);
  font-weight: 500;
}
