/* ==========================================
   Mahjong Break Point Trainer - Full Game UI
   ========================================== */

:root {
  --bg-dark: #f8fafc;        /* White background */
  --bg-card: #16a34a;        /* Solid Green cards */
  --bg-card-hover: #15803d;  
  
  --table-felt: #22c55e;     
  --table-felt-dark: #16a34a;
  --table-border: #14532d;   
  --table-frame: #166534;
  
  --tile-bg-start: #facc15;
  --tile-bg-end: #eab308;
  --tile-border: #ca8a04;
  --tile-shadow: rgba(0, 0, 0, 0.25);
  
  --gold: #16a34a;           /* Re-mapped to Main Green */
  --gold-light: #22c55e;     /* Bright Green */
  --gold-dark: #15803d;      /* Dark Green */
  
  --text-primary: #ffffff;   /* Text on green cards */
  --text-secondary: #dcfce7; /* Subtext on green cards */
  --text-dim: #bbf7d0;
  
  --text-global: #064e3b;    /* Text on white background */
  
  --correct: #f59e0b;        /* Amber for contrast */
  --correct-glow: rgba(245, 158, 11, 0.5);
  --incorrect: #ef4444;
  --incorrect-glow: rgba(239, 68, 68, 0.5);
  
  --dead-wall-start: #93c5fd;
  --dead-wall-end: #60a5fa;
  --urgent: #ef4444;
  
  font-family: 'Noto Sans JP', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  margin: 0; padding: 0;
  font-family: 'Noto Sans JP', sans-serif;
  background-color: var(--bg-dark); color: var(--text-global);
  height: 100dvh; width: 100vw; overflow: hidden;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%; height: 100dvh; position: relative; overflow: hidden;
}

/* ── Screen Management ── */
.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 20;
}

/* ===== START SCREEN ===== */
.start-content {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; width: 100%; gap: 2vh;
  padding-top: 2vh;
}
.start-hero {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 16px 8px;
}
.subtitle-wrap {
  display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 8px;
}
.hero-logo-small {
  width: clamp(60px, 10vh, 90px); height: auto; margin: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
.start-hero h1 {
  font-size: clamp(3rem, 8vh, 4.2rem); font-weight: 900;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  margin-bottom: 8px; text-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
  line-height: 1.1;
}
.hero-subtitle {
  font-size: 1.3rem; color: var(--gold-dark); font-weight: 700;
  letter-spacing: 2px; margin: 0;
}
.hero-tagline { color: var(--text-global); font-size: 1.1rem; font-weight: 600; }
.hero-credits {
  margin-top: clamp(8px, 2vh, 24px); display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.hero-credits p { font-size: 0.85rem; font-weight: 700; color: var(--gold-dark); }
.x-link {
  display: inline-flex; align-items: center; justify-content: center;
  background: #ffffff; color: var(--gold-dark); text-decoration: none;
  padding: 8px 16px; border-radius: 20px; font-size: 0.85rem; font-weight: 700;
  border: 2px solid var(--gold-light); transition: all 0.2s;
}
.x-link:hover {
  background: var(--gold-light); border-color: var(--gold-dark); color: #ffffff;
  transform: translateY(-2px);
}

.mode-cards { display: grid; grid-auto-rows: 1fr; gap: 2vh; width: 100%; max-width: 440px; margin-top: 0; }
.mode-card {
  background: #ffffff; border: 2px solid var(--gold-light);
  border-radius: 20px; padding: clamp(12px, 2vh, 16px) 20px; display: flex; align-items: center; gap: 16px;
  cursor: pointer; text-align: left; transition: all 0.2s; position: relative; overflow: hidden;
  color: var(--text-global);
}
.mode-card:hover {
  background: var(--bg-dark); border-color: var(--gold-dark);
  transform: translateY(-2px); box-shadow: 0 8px 24px rgba(34, 197, 94, 0.2);
}
.mode-emoji { 
  font-size: 2.8rem; 
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.mode-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.mode-name { font-size: 1.3rem; font-weight: 700; color: var(--gold-dark); }
.mode-desc { font-size: 0.9rem; color: var(--text-global); font-weight: 600; }
.mode-best {
  font-size: 0.85rem; font-weight: 700; color: var(--gold-dark);
  background: var(--bg-dark); border: 1px solid var(--gold-light); padding: 4px 8px; border-radius: 8px; text-align: right;
}

.start-controls { display: flex; gap: 12px; margin-top: 2vh; width: 100%; max-width: 440px; justify-content: space-between; }
.total-plays { color: var(--text-global); font-weight: 600; font-size: 1.1rem; margin-top: auto; }

/* ===== HUD ===== */
#hud {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; height: 44px; z-index: 30;
}
#hud-left, #hud-right { flex: 1; display: flex; gap: 8px; align-items: center; }
#hud-center {
  flex: 2; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#hud-right { justify-content: flex-end; }

.hud-slot {
  background: #ffffff; border: 2px solid var(--gold-light); color: var(--gold-dark);
  padding: 6px 12px; border-radius: 12px; display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 1.1rem; min-width: 80px; justify-content: center;
  box-shadow: 0 4px 12px rgba(34,197,94,0.1);
}
#hud-lives { white-space: nowrap; font-size: 1.2rem; letter-spacing: 2px; }
.hud-icon { font-size: 1.1rem; }
.hud-icon-sm { font-size: 0.9rem; }
.hud-tiny { font-size: 0.7rem; color: var(--gold-dark); margin-left: 2px; }

#hud-timer.urgent { color: var(--urgent); border-color: var(--urgent); animation: pulseUrgent 0.5s infinite alternate; }
@keyframes pulseUrgent { from { box-shadow: 0 0 4px var(--urgent); } to { box-shadow: 0 0 16px var(--urgent); } }

#hud-score-wrap { position: relative; font-size: 1.4rem; font-weight: 900; color: var(--gold-dark); display: flex; align-items: baseline; gap: 4px; }
.hud-pts { font-size: 0.8rem; color: var(--gold); }
.score-pop {
  position: absolute; right: -40px; top: -10px; color: var(--correct); font-size: 0.9rem;
  font-weight: 700; opacity: 0; pointer-events: none;
}
.score-pop.anim { animation: scorePopAnim 0.8s ease-out; }
@keyframes scorePopAnim {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  50% { transform: translateY(-15px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-25px) scale(1); }
}

#hud-streak-wrap { color: #f59e0b; font-weight: 700; font-size: 0.9rem; margin-top: -4px; }

/* ── Table & Game Area ── */
#table {
  --ts: 1;
  --sw: calc(22px * var(--ts));  
  --sd: calc(28px * var(--ts));  
  --gw: calc(2px * var(--ts));   
  width: min(800px, 92vw, calc(100vh - 240px));
  aspect-ratio: 1;
  position: relative;
  background:
    radial-gradient(ellipse at 40% 40%, rgba(255,255,255,0.15), transparent 60%),
    radial-gradient(ellipse at center, var(--table-felt), var(--table-felt-dark));
  border: calc(6px * var(--ts)) solid var(--table-frame);
  border-radius: calc(16px * var(--ts));
  box-shadow:
    inset 0 0 calc(80px * var(--ts)) rgba(0,0,0,0.3),
    0 calc(8px * var(--ts)) calc(32px * var(--ts)) rgba(34,197,94,0.3),
    0 0 0 calc(2px * var(--ts)) var(--table-border);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
#table.flash-error {
  box-shadow: inset 0 0 calc(120px * var(--ts)) rgba(239, 68, 68, 0.4), 0 0 0 calc(2px * var(--ts)) var(--urgent);
}

#table::before {
  content: ''; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}

.wind-label {
  position: absolute; font-size: calc(0.95rem * var(--ts)); font-weight: 700;
  color: rgba(255,255,255,0.7); display: flex; flex-direction: column;
  align-items: center; gap: calc(1px * var(--ts));
  pointer-events: none; z-index: 6; user-select: none;
  transition: color 0.4s, text-shadow 0.4s;
}
.wind-label.highlight { color: #ffffff; text-shadow: 0 0 calc(16px * var(--ts)) rgba(255,255,255,0.8); }
.wind-sub { font-size: calc(0.55rem * var(--ts)); font-weight: 400; opacity: 0.9; }
.wind-assist {
  font-size: calc(0.6rem * var(--ts)); color: #000; background: rgba(255,255,255,0.8);
  padding: calc(2px * var(--ts)) calc(6px * var(--ts)); border-radius: calc(8px * var(--ts));
  border: 1px solid rgba(0,0,0,0.1); margin-top: calc(2px * var(--ts)); display: none;
}
.assists-visible .wind-assist { display: block; }
#wind-top    { top: 22%; left: 50%; transform: translateX(-50%); }
#wind-right  { right: 20%; top: 50%; transform: translateY(-50%); }
#wind-bottom { bottom: 20%; left: 50%; transform: translateX(-50%); }
#wind-left   { left: 20%; top: 50%; transform: translateY(-50%); }

.wall { position: absolute; display: flex; z-index: 4; }
.wall-h { flex-direction: row; gap: 0; }
.wall-v { flex-direction: column; gap: 0; }
.wall.clickable, .wind-label.clickable { cursor: pointer; transition: all 0.2s; border-radius: 8px; }
.wind-label.clickable:hover { background: rgba(34, 197, 94, 0.25); box-shadow: 0 0 12px rgba(34,197,94,0.4); transform: scale(1.1); }
.wall.clickable::after {
  content: ''; position: absolute; inset: -8px; border-radius: 12px;
  pointer-events: none; transition: all 0.2s; border: 2px solid transparent; z-index: -1;
}
.wall.clickable:hover::after {
  border-color: #4ade80; background: rgba(34, 197, 94, 0.5);
  box-shadow: 0 0 24px 4px rgba(34, 197, 94, 0.8); border-width: 3px;
}
.wall.correct-answer::after {
  content: ''; position: absolute; inset: -8px; border-radius: 12px; pointer-events: none; z-index: -1;
  background: var(--correct); box-shadow: 0 0 calc(20px * var(--ts)) var(--correct-glow); border: 3px solid var(--correct);
}
#wall-top    { top: 8%; left: 50%; transform: translateX(-50%); }
#wall-bottom { bottom: 8%; left: 50%; transform: translateX(-50%); }
#wall-right  { right: 7%; top: 50%; transform: translateY(-50%); }
#wall-left   { left: 7%; top: 50%; transform: translateY(-50%); }

.stack {
  --bamboo-angle: 90deg;
  width: var(--sw); height: var(--sd);
  background: 
    repeating-linear-gradient(var(--bamboo-angle), transparent 0px, transparent 1px, rgba(0,0,0,0.08) 2px, transparent 3px),
    repeating-linear-gradient(var(--bamboo-angle), transparent 0px, transparent 2px, rgba(255,255,255,0.25) 3px, transparent 4px),
    linear-gradient(145deg, var(--tile-bg-start), var(--tile-bg-end));
  border: 1px solid var(--tile-border); border-radius: calc(3px * var(--ts));
  box-shadow: 0 calc(1px * var(--ts)) calc(3px * var(--ts)) var(--tile-shadow), inset 0 calc(1px * var(--ts)) 0 rgba(255,255,255,0.4);
  flex-shrink: 0; position: relative; z-index: 1; transition: opacity 0.4s;
}
.wall-v .stack { --bamboo-angle: 0deg; width: var(--sd); height: var(--sw); }
.stack.dead-wall-area {
  background: linear-gradient(145deg, var(--dead-wall-start), var(--dead-wall-end)) !important;
  border-color: #60a5fa !important; box-shadow: 0 0 calc(8px * var(--ts)) rgba(96,165,250,0.4) !important; opacity: 0.9;
}
.stack.dimmed { opacity: 0.3; }

.stack-gap { flex-shrink: 0; position: relative; z-index: 10; }
.wall-h .stack-gap { width: var(--gw); height: var(--sd); }
.wall-v .stack-gap { height: var(--gw); width: var(--sd); }
.stack-gap::before {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 15;
}
.wall-h .stack-gap::before { width: calc(19.5px * var(--ts)); height: calc(var(--sd) + 48px * var(--ts)); }
.wall-v .stack-gap::before { height: calc(19.5px * var(--ts)); width: calc(var(--sd) + 48px * var(--ts)); }
.stack-gap.clickable, .stack-gap.clickable::before { cursor: pointer; }
.stack-gap::after {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  border-radius: calc(2px * var(--ts)); pointer-events: none; opacity: 0;
  transition: opacity 0.15s, background 0.15s, box-shadow 0.15s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.wall-h .stack-gap::after { width: calc(3px * var(--ts)); height: calc(var(--sd) + 8px * var(--ts)); }
.wall-v .stack-gap::after { height: calc(3px * var(--ts)); width: calc(var(--sd) + 8px * var(--ts)); }

.stack-gap.clickable:hover::after {
  opacity: 1; background: #ffffff;
  box-shadow: 0 0 calc(10px * var(--ts)) #ffffff, 0 0 calc(20px * var(--ts)) rgba(255,255,255,0.6);
}
.stack-gap.correct-answer::after {
  opacity: 1; background: var(--correct); box-shadow: 0 0 calc(14px * var(--ts)) var(--correct-glow);
  transform: translate(-50%, -50%) scale(1.5);
}
.stack-gap.incorrect-answer::after {
  opacity: 1; background: var(--incorrect); box-shadow: 0 0 calc(14px * var(--ts)) var(--incorrect-glow);
}

.particle {
  position: absolute; top: 50%; left: 50%; width: calc(4px * var(--ts)); height: calc(4px * var(--ts));
  background: var(--correct); border-radius: 50%; pointer-events: none; z-index: 20;
  box-shadow: 0 0 6px var(--correct); animation: particle-anim 0.6s ease-out forwards;
}
@keyframes particle-anim {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

#center {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: calc(6px * var(--ts));
  z-index: 5; pointer-events: none;
}

#combo-box {
  background: #ffffff; border: 2px solid var(--gold-light); padding: calc(4px * var(--ts)) calc(12px * var(--ts));
  border-radius: calc(16px * var(--ts)); display: flex; align-items: center; gap: calc(4px * var(--ts));
  box-shadow: 0 4px 12px rgba(34,197,94,0.2); margin-bottom: calc(4px * var(--ts));
}
#combo-box.anim-pop { animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#combo-fire { font-size: calc(1.1rem * var(--ts)); }
#combo-num { color: var(--gold-dark); font-size: calc(1.1rem * var(--ts)); font-weight: 900; }
.combo-txt { color: var(--gold-dark); font-size: calc(0.7rem * var(--ts)); font-weight: 700; margin-top: calc(2px * var(--ts));}
#combo-mult { color: var(--correct); font-size: calc(0.8rem * var(--ts)); font-weight: 700; margin-left: calc(4px * var(--ts));}

#dice-container { display: flex; gap: calc(14px * var(--ts)); margin-bottom: calc(2px * var(--ts)); }
.die {
  width: calc(50px * var(--ts)); height: calc(50px * var(--ts));
  background: linear-gradient(135deg, #ffffff, #f0f0f0); border-radius: calc(10px * var(--ts));
  box-shadow: 0 calc(4px * var(--ts)) calc(10px * var(--ts)) rgba(0,0,0,0.2), inset 0 calc(-2px * var(--ts)) calc(4px * var(--ts)) rgba(0,0,0,0.08);
  padding: calc(7px * var(--ts)); transition: transform 0.1s;
}
.die-face {
  width: 100%; height: 100%; display: grid; grid-template-rows: repeat(3,1fr); grid-template-columns: repeat(3,1fr);
}
.dot {
  width: calc(8px * var(--ts)); height: calc(8px * var(--ts));
  background: radial-gradient(circle at 35% 35%, #e03050, #b01830); border-radius: 50%;
  align-self: center; justify-self: center; box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}
.die.rolling { animation: dieRoll 0.08s infinite alternate; }
@keyframes dieRoll { 0% { transform: rotate(-8deg) scale(0.92); } 100% { transform: rotate(8deg) scale(1.08); } }
.die.bounce { animation: dieBounce 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes dieBounce { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }

#dice-info {
  background: #ffffff; padding: calc(4px * var(--ts)) calc(18px * var(--ts));
  border-radius: calc(20px * var(--ts)); font-size: calc(1rem * var(--ts));
  font-weight: 700; color: var(--gold-dark); border: 2px solid var(--gold-light);
  box-shadow: 0 4px 12px rgba(34,197,94,0.15);
}
#result-msg {
  font-size: calc(0.9rem * var(--ts)); font-weight: 700; text-align: center;
  min-height: 1.2em; line-height: 1.4;
  background: #ffffff; padding: calc(4px * var(--ts)) calc(12px * var(--ts));
  border-radius: calc(8px * var(--ts)); margin-top: calc(4px * var(--ts)); display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
#result-msg.active { display: block; }
#result-msg.correct { color: var(--gold-dark); border: 2px solid var(--gold-light); }
#result-msg.incorrect { color: var(--incorrect); border: 2px solid var(--incorrect); }

/* Buttons */
#action-area { display: flex; gap: 12px; margin-top: 16px; min-height: 48px; }
.action-btn {
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark)); color: #ffffff;
  border: none; padding: 14px 32px; border-radius: 14px; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: inherit; box-shadow: 0 4px 16px rgba(34,197,94,0.3);
}
.action-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(34,197,94,0.5); background: linear-gradient(135deg, var(--gold), var(--gold-dark)); }
.action-btn:active { transform: translateY(0); }
.action-btn-sec {
  background: #ffffff; color: var(--gold-dark); border: 2px solid var(--gold-dark);
  padding: 14px 32px; border-radius: 14px; font-size: 1.05rem; font-weight: 700; cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.action-btn-sec:hover { background: var(--gold-light); color: #ffffff; border-color: var(--gold-dark); }

.pulse-glow { animation: pulseGlow 2.5s ease-in-out infinite; }
@keyframes pulseGlow { 0%, 100% { box-shadow: 0 4px 16px rgba(34,197,94,0.3); } 50% { box-shadow: 0 4px 28px rgba(34,197,94,0.6), 0 0 40px rgba(34,197,94,0.15); } }

/* Shared Icon Buttons */
.icon-btn, .icon-btn-sm {
  background: #ffffff; border: 2px solid var(--gold-light); color: var(--gold-dark);
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; font-family: inherit;
}
.icon-btn { width: 56px; height: 56px; font-size: 1.6rem; }
.icon-btn-sm { width: 36px; height: 36px; font-size: 1rem; }
.icon-btn:hover, .icon-btn-sm:hover { background: var(--bg-dark); border-color: var(--gold-dark); }
.icon-btn.active {
  background: var(--gold-dark); border-color: var(--gold-dark); color: #ffffff; box-shadow: 0 4px 12px rgba(34,197,94,0.3);
}

/* Icon Buttons with Text */
.icon-btn-text {
  background: #ffffff; border: 2px solid var(--gold-light); color: var(--text-global);
  border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: all 0.2s; font-family: inherit;
  flex: 1 1 0; height: clamp(56px, 8vh, 70px); gap: 4px; font-weight: 600; padding: 4px; box-sizing: border-box;
}
.icon-btn-text .icon { 
  font-size: 1.8rem; line-height: 1; 
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.icon-btn-text .lbl { font-size: 0.75rem; color: var(--text-global); white-space: nowrap; font-weight: bold; }
.icon-btn-text:hover { background: var(--bg-dark); border-color: var(--gold-dark); }
.icon-btn-text.active {
  background: var(--gold-dark); border-color: var(--gold-dark); box-shadow: 0 4px 12px rgba(34,197,94,0.3);
}
.icon-btn-text.active .icon { background: none; -webkit-text-fill-color: initial; color: #ffffff; }
.icon-btn-text.active .lbl { color: #ffffff; }

/* Practice Stats */
#prac-stats { display: flex; gap: 16px; margin-top: 12px; }
.mini-stat { display: flex; flex-direction: column; align-items: center; background: #ffffff; border: 1px solid var(--gold-light); padding: 8px 16px; border-radius: 12px; }
.mini-val { font-size: 1.1rem; font-weight: 700; color: var(--gold-dark); }
.mini-lbl { font-size: 0.7rem; color: var(--text-global); margin-top: 2px; font-weight: 600; }

/* ===== RESULT SCREEN ===== */
.result-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; max-width: 400px; padding: 24px; background: #ffffff;
  border: 2px solid var(--gold-light); border-radius: 24px; box-shadow: 0 12px 40px rgba(34,197,94,0.2);
  margin-top: 20px;
}
.result-heading { color: var(--gold-dark); font-size: 1.1rem; font-weight: 700; letter-spacing: 2px; margin-bottom: 24px; }
#rank-circle {
  width: 120px; height: 120px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 4rem; font-weight: 900; margin-bottom: 16px; box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); transform: scale(0.5); opacity: 0;
}
#rank-circle.show { transform: scale(1); opacity: 1; }
.rank-s { background: linear-gradient(135deg, #fbbf24, #d97706); color: #fff; box-shadow: 0 8px 24px rgba(251,191,36,0.4); }
.rank-a { background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; box-shadow: 0 8px 24px rgba(239,68,68,0.3); }
.rank-b { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; box-shadow: 0 8px 24px rgba(59,130,246,0.3); }
.rank-c { background: linear-gradient(135deg, #22c55e, #15803d); color: #fff; box-shadow: 0 8px 24px rgba(34,197,94,0.3); }
.rank-d { background: linear-gradient(135deg, #9ca3af, #4b5563); color: #fff; }

#new-best { color: var(--gold-dark); font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; animation: bounce 1s infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.result-score { font-size: 2.5rem; font-weight: 900; color: var(--gold-dark); margin-bottom: 24px; }
.res-pts { font-size: 1rem; color: var(--gold); margin-left: 4px; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin-bottom: 32px; }
.rg { background: var(--bg-dark); border: 1px solid var(--gold-light); padding: 12px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; }
.rg-l { font-size: 0.75rem; color: var(--text-global); font-weight: 600; margin-bottom: 4px; }
.rg-v { font-size: 1.2rem; font-weight: 700; color: var(--gold-dark); }

.result-btns { display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* ===== MODALS ===== */
.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal.visible { opacity: 1; pointer-events: auto; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal-content {
  position: relative; background: #ffffff; border: 2px solid var(--gold-light); border-radius: 20px;
  padding: clamp(16px, 3vh, 28px); max-width: 480px; width: 92%; max-height: 95dvh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(34,197,94,0.3); transform: translateY(20px); transition: transform 0.3s;
  color: var(--text-global);
}
.modal.visible .modal-content { transform: translateY(0); }
.modal-content h2 { font-size: 1.3rem; margin-bottom: clamp(8px, 1.5vh, 16px); color: var(--gold-dark); }
.rules-body { margin-bottom: clamp(12px, 2vh, 24px); }
.rules-intro { color: var(--text-global); line-height: 1.7; margin-bottom: clamp(8px, 1.5vh, 16px); font-size: 0.9rem; font-weight: 600; }
.rules-intro strong { color: var(--gold-dark); }
.rule-sec { margin-bottom: clamp(12px, 2vh, 20px); }
.rule-sec h3 { font-size: 0.95rem; color: var(--gold-dark); margin-bottom: clamp(4px, 1vh, 8px); }
.rule-sec p { color: var(--text-global); font-size: 0.88rem; line-height: 1.6; margin-bottom: 6px; }
.rule-sec ol, .rule-sec ul { padding-left: 20px; color: var(--text-global); line-height: 1.8; font-size: 0.88rem; }
.rule-sec strong { color: var(--gold-dark); }
.rtbl { width: 100%; border-collapse: collapse; margin-top: clamp(4px, 1vh, 8px); }
.rtbl th, .rtbl td { padding: clamp(4px, 1vh, 8px) 12px; border: 1px solid var(--gold-light); text-align: center; font-size: 0.88rem; }
.rtbl th { background: var(--gold-light); color: #ffffff; font-weight: 600; }
.rtbl td { color: var(--text-global); font-weight: 600; }

/* Utilities */
.hidden { display: none !important; }
.animate-in { animation: fadeInUp 0.3s ease-out; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 500px) {
  #app { padding: 10px; }
  .start-hero h1 { font-size: 2.4rem; }
  .hero-subtitle { font-size: 1rem; }
  .mode-card { padding: 12px 16px; }
  .action-btn { padding: 12px 24px; font-size: 0.95rem; }
  .hud-slot { padding: 4px 8px; font-size: 0.95rem; min-width: 60px; }
  #hud-score-wrap { font-size: 1.2rem; }
  .result-grid { gap: 8px; }
  .rg-v { font-size: 1.1rem; }
}
