:root {
  --bg-deep: #070b14;
  --bg-navy: #0f172a;
  --bg-card: rgba(17, 24, 39, 0.86);
  --bg-elevated: rgba(30, 41, 59, 0.72);
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.32);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-primary: #38bdf8;
  --accent-indigo: #6366f1;
  --accent-grad: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  --accent-warn: #f59e0b;
  --accent-danger: #ef4444;
  --accent-success: #10b981;

  --r-color: #ff4d6d;
  --g-color: #22c55e;
  --b-color: #3b82f6;

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.14), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(99, 102, 241, 0.16), transparent 45%),
    linear-gradient(180deg, #070b14 0%, #0b1120 100%);
  color: var(--text-main);
  font-family: 'Noto Sans JP', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  animation: fadeIn 0.22s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

.section-label {
  margin: 0 0 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* Badges */
.brand-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.badge-easy {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-hard {
  background: rgba(244, 63, 94, 0.18);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.4);
}

.badge-retry {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.38);
}

.badge-timeup {
  background: rgba(239, 68, 68, 0.22);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.55);
  animation: pulseBadge 1.4s ease-in-out infinite;
}

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

.progress-pill {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-lg {
  min-height: 54px;
  padding: 14px 20px;
  font-size: 1.05rem;
}

.btn-primary {
  background: var(--accent-grad);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.28);
}

.btn-primary:hover {
  filter: brightness(1.07);
}

.btn-secondary {
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
  border: 1.5px solid rgba(245, 158, 11, 0.45);
}

.btn-secondary:hover {
  background: rgba(245, 158, 11, 0.22);
}

/* Start Screen */
.start-hero {
  text-align: center;
  padding: 14px 4px 4px;
}

.game-title {
  margin: 12px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.title-main {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  background: linear-gradient(135deg, #ffffff 0%, #bae6fd 55%, #a5b4fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.24em;
  color: var(--text-muted);
}

.hero-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.difficulty-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.diff-btn {
  width: 100%;
  text-align: left;
  background: rgba(15, 23, 42, 0.8);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  color: var(--text-main);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  touch-action: manipulation;
}

.diff-btn:active {
  transform: scale(0.99);
}

.diff-btn.selected {
  border-color: var(--accent-primary);
  background: rgba(56, 189, 248, 0.1);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25), 0 8px 20px rgba(56, 189, 248, 0.12);
}

.diff-btn[data-difficulty="HARD"].selected {
  border-color: #fb7185;
  background: rgba(244, 63, 94, 0.11);
  box-shadow: 0 0 0 1px rgba(244, 63, 94, 0.25), 0 8px 20px rgba(244, 63, 94, 0.14);
}

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

.diff-name {
  font-family: 'Inter', sans-serif;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.diff-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.diff-tag-hard {
  background: rgba(244, 63, 94, 0.18);
  color: #fda4af;
}

.diff-desc {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.rules-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
}

.rule-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
}

.rule-key {
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}

.rule-val {
  color: var(--text-main);
  font-weight: 700;
  text-align: right;
}

/* Game Screen */
.game-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.header-title {
  font-size: 0.95rem;
  font-weight: 900;
  color: var(--text-main);
}

.timer-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.timer-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-main);
  min-width: 96px;
}

.timer-display.warning {
  color: #fbbf24;
}

.timer-display.danger {
  color: #f87171;
  animation: pulseTimer 0.7s ease-in-out infinite;
}

@keyframes pulseTimer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.timer-icon {
  font-size: 1.1rem;
}

.timer-track {
  flex: 1;
  height: 10px;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent-grad);
  border-radius: 999px;
  transition: width 0.2s linear, background-color 0.2s ease;
}

.timer-fill.warning {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.timer-fill.danger {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

/* Color Stage */
.color-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-stage.single-color {
  grid-template-columns: 1fr;
}

.color-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
  text-align: center;
}

.color-box {
  width: 100%;
  height: 126px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), 0 8px 20px rgba(0, 0, 0, 0.35);
  transition: background-color 0.06s linear;
}

.color-stage.single-color .color-box {
  height: 142px;
}

/* RGB Controls */
.rgb-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px 16px 18px;
}

.rgb-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rgb-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rgb-channel-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 1.05rem;
  font-weight: 900;
}

.channel-sub {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.channel-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.rgb-r .channel-dot { background: var(--r-color); box-shadow: 0 0 10px rgba(255, 77, 109, 0.6); }
.rgb-g .channel-dot { background: var(--g-color); box-shadow: 0 0 10px rgba(34, 197, 94, 0.6); }
.rgb-b .channel-dot { background: var(--b-color); box-shadow: 0 0 10px rgba(59, 130, 246, 0.6); }

.rgb-num-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-btn {
  width: 42px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 1.2rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.step-btn:active {
  background: rgba(148, 163, 184, 0.3);
  transform: scale(0.95);
}

.rgb-input {
  width: 68px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: #090e1a;
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
  padding: 0 4px;
  -moz-appearance: textfield;
}

.rgb-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.rgb-input::-webkit-inner-spin-button,
.rgb-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Large Touch-Friendly Range Sliders */
.rgb-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  touch-action: pan-y;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.slider-r {
  background: linear-gradient(90deg, #1a060a 0%, #ff2e55 100%);
}

.slider-g {
  background: linear-gradient(90deg, #051b0e 0%, #22c55e 100%);
}

.slider-b {
  background: linear-gradient(90deg, #061026 0%, #3b82f6 100%);
}

.rgb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid #0f172a;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.rgb-slider:active::-webkit-slider-thumb {
  transform: scale(1.1);
}

.rgb-slider::-moz-range-thumb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid #0f172a;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(255, 255, 255, 0.45);
  cursor: pointer;
}

.slider-r::-webkit-slider-thumb { border-color: var(--r-color); }
.slider-g::-webkit-slider-thumb { border-color: var(--g-color); }
.slider-b::-webkit-slider-thumb { border-color: var(--b-color); }

.slider-r::-moz-range-thumb { border-color: var(--r-color); }
.slider-g::-moz-range-thumb { border-color: var(--g-color); }
.slider-b::-moz-range-thumb { border-color: var(--b-color); }

/* Result Screen */
.result-header,
.final-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-meta,
.final-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.result-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 900;
}

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

.score-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.score-block,
.rank-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rank-block {
  align-items: center;
}

.score-caption {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.score-value {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.1;
  color: #ffffff;
}

.score-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.rank-badge {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.rank-lg {
  width: 74px;
  height: 74px;
  font-size: 2.6rem;
  border-radius: 20px;
}

.rank-s { background: linear-gradient(135deg, #facc15, #f97316); color: #1e1b4b; }
.rank-a { background: linear-gradient(135deg, #38bdf8, #6366f1); color: #ffffff; }
.rank-b { background: linear-gradient(135deg, #34d399, #059669); color: #ffffff; }
.rank-c { background: linear-gradient(135deg, #94a3b8, #475569); color: #ffffff; }
.rank-d { background: linear-gradient(135deg, #fb7185, #be123c); color: #ffffff; }

.rank-text {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-main);
}

.first-score-note {
  font-size: 0.82rem;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}

.result-colors .color-box {
  height: 102px;
}

.rgb-code {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

.diff-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.ch-tag {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-weight: 900;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.ch-r { background: rgba(255, 77, 109, 0.24); border: 1px solid var(--r-color); color: #ff8fa3; }
.ch-g { background: rgba(34, 197, 94, 0.22); border: 1px solid var(--g-color); color: #86efac; }
.ch-b { background: rgba(59, 130, 246, 0.24); border: 1px solid var(--b-color); color: #93c5fd; }

.diff-vals {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.diff-vals strong {
  color: var(--text-main);
}

.diff-delta {
  font-size: 0.88rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-main);
  min-width: 58px;
  text-align: center;
}

.diff-delta.exact {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

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

/* Final Result Screen */
.final-summary-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.final-rank-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.final-rank-title {
  font-size: 1.25rem;
  font-weight: 900;
}

.final-rank-comment {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.final-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-box {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: #ffffff;
}

.question-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.q-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(15, 23, 42, 0.68);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.q-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.q-swatches {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.q-swatch {
  width: 28px;
  height: 36px;
  border-radius: 7px;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
}

.q-swatch + .q-swatch {
  margin-left: -6px;
}

.q-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.q-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.q-num {
  font-size: 0.88rem;
  font-weight: 800;
}

.q-mini-tag {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.q-mini-tag.timeup {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.q-rgb-sub {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.74rem;
  line-height: 1.35;
  color: var(--text-muted);
}

.q-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.q-score {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
}

.q-first-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
}

@media (max-width: 375px) {
  .color-box {
    height: 106px;
  }
  .color-stage.single-color .color-box {
    height: 122px;
  }
  .rgb-input {
    width: 60px;
  }
  .step-btn {
    width: 38px;
  }
}
