:root {
  --bg: #08080f;
  --bg-glow: radial-gradient(circle at 50% 0%, #16162a 0%, #08080f 60%);
  --panel: #12121f;
  --panel-border: #23233a;
  --text: #f4f4fa;
  --text-dim: #9797ad;
  --red: #ff2e63;
  --red-glow: rgba(255, 46, 99, 0.55);
  --blue: #2e8bff;
  --blue-glow: rgba(46, 139, 255, 0.55);
  --yellow: #ffe200;
  --yellow-glow: rgba(255, 226, 0, 0.5);
  --accent: #29ffa0;
  --accent-glow: rgba(41, 255, 160, 0.5);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg-glow), var(--bg);
  color: var(--text);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 16px 8px;
}

.app-header {
  text-align: center;
  margin-bottom: 12px;
}

.app-header h1 {
  font-weight: 800;
  font-size: 1.6rem;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}

.app-header .accent {
  color: var(--accent);
  text-shadow: 0 0 16px var(--accent-glow);
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.best-score-bar {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 20px;
  margin: 0 auto 16px;
  width: fit-content;
}

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

.best-value {
  font-weight: 800;
  font-size: 1rem;
  color: var(--accent);
}

.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 480px;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none;
}

#startScreen,
#resultScreen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 32px 24px;
}

.level-select {
  display: flex;
  gap: 10px;
}

.level-button {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 88px;
  border-radius: 20px;
  padding: 12px 16px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  background: var(--bg);
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.level-button:active {
  transform: scale(0.93);
}

.level-button .level-name {
  font-weight: 800;
  font-size: 1rem;
}

.level-button .level-stars {
  font-size: 0.8rem;
  letter-spacing: 3px;
}

.level-beginner { border: 2px solid var(--accent); color: var(--accent); }
.level-intermediate { border: 2px solid var(--yellow); color: var(--yellow); }
.level-advanced { border: 2px solid var(--red); color: var(--red); }

.level-button.active.level-beginner {
  background: var(--accent);
  color: #08080f;
  box-shadow: 0 0 20px var(--accent-glow);
  transform: scale(1.06);
}

.level-button.active.level-intermediate {
  background: var(--yellow);
  color: #08080f;
  box-shadow: 0 0 20px var(--yellow-glow);
  transform: scale(1.06);
}

.level-button.active.level-advanced {
  background: var(--red);
  color: #08080f;
  box-shadow: 0 0 20px var(--red-glow);
  transform: scale(1.06);
}

.rule-text {
  color: var(--text-dim);
  line-height: 1.9;
  font-size: 0.95rem;
  margin: 0;
}

.primary-button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 16px 48px;
  font-family: inherit;
  font-weight: 800;
  font-size: 1.1rem;
  color: #08080f;
  background: var(--accent);
  box-shadow: 0 0 24px var(--accent-glow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease;
}

.primary-button:active {
  transform: scale(0.94);
}

/* --- game screen --- */

#gameScreen {
  gap: 10px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0 4px;
}

.round-indicator {
  color: var(--text-dim);
}

.timer {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-size: 1.1rem;
}

.target-banner {
  text-align: center;
  font-weight: 800;
  font-size: 1.3rem;
  padding: 10px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  transition: box-shadow 0.15s ease;
}

.target-banner.target-red { color: var(--red); text-shadow: 0 0 14px var(--red-glow); }
.target-banner.target-blue { color: var(--blue); text-shadow: 0 0 14px var(--blue-glow); }
.target-banner.target-yellow { color: var(--yellow); text-shadow: 0 0 14px var(--yellow-glow); }

.target-banner.memory-reveal {
  color: var(--text);
  animation: reveal-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes reveal-pulse {
  from { box-shadow: inset 0 0 0 1px var(--panel-border); }
  to { box-shadow: inset 0 0 0 1px rgba(244, 244, 250, 0.5), 0 0 16px rgba(244, 244, 250, 0.25); }
}

.play-area {
  position: relative;
  flex: 1;
  min-height: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  overflow: hidden;
  touch-action: none;
}

.play-area.shake {
  animation: shake 0.25s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.circle {
  position: absolute;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  animation: pop-in 0.18s ease-out;
}

@keyframes pop-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.circle.popping {
  animation: pop-out 0.18s ease-in forwards;
  pointer-events: none;
}

@keyframes pop-out {
  to { transform: scale(0); opacity: 0; }
}

.circle.wrong-tap {
  animation: wrong-shake 0.22s ease;
}

@keyframes wrong-shake {
  0%, 100% { transform: scale(1) rotate(0); }
  30% { transform: scale(0.9) rotate(-8deg); }
  60% { transform: scale(0.9) rotate(8deg); }
}

.circle.color-red { background: var(--red); box-shadow: 0 0 18px var(--red-glow); }
.circle.color-blue { background: var(--blue); box-shadow: 0 0 18px var(--blue-glow); }
.circle.color-yellow { background: var(--yellow); box-shadow: 0 0 18px var(--yellow-glow); }

.circle.concealed {
  background: #2a2a42;
  box-shadow: inset 0 0 0 2px rgba(244, 244, 250, 0.18);
  transition: background 0.12s ease;
}

/* --- result screen --- */

.result-label {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.9rem;
}

.result-time {
  font-size: 2.6rem;
  font-weight: 800;
  margin: 0;
}

.result-time .unit {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-left: 4px;
}

.result-record {
  color: var(--accent);
  font-weight: 800;
  margin: 0;
  text-shadow: 0 0 14px var(--accent-glow);
}

.result-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 20px 0 12px;
}

.site-footer p {
  margin: 2px 0;
}

.site-footer a {
  color: var(--text-dim);
}
