:root {
  --ns-cyan: #22d3ee;
  --ns-purple: #a855f7;
  --ns-amber: #f59e0b;
  --ns-pink: #f43f5e;
  --ns-bg: #050914;
  --ns-glass: rgba(12, 18, 38, 0.55);
  --ns-glass-strong: rgba(8, 13, 28, 0.78);
  --ns-border: rgba(148, 210, 255, 0.22);
  --ns-text: #eaf6ff;
  --ns-text-dim: rgba(234, 246, 255, 0.6);
  --ns-radius: 14px;
  --ns-safe-t: env(safe-area-inset-top, 0px);
  --ns-safe-b: env(safe-area-inset-bottom, 0px);
  --ns-safe-l: env(safe-area-inset-left, 0px);
  --ns-safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* Author rules below set `display` on several of these same elements (.ns-overlay,
   .ns-icon-btn, ...) toggled via the native `hidden` attribute/property from JS. An
   author `display` declaration beats the UA `[hidden]{display:none}` rule regardless
   of selector specificity, so without this override every "hidden" screen paints
   anyway, stacked on top of each other in DOM order. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ns-bg);
  color: var(--ns-text);
  font-family: 'Segoe UI', 'Pretendard', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#ns-stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#app {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.ns-ui { position: absolute; inset: 0; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Glass primitives ---------- */

.ns-panel, .ns-glass-card {
  background: var(--ns-glass);
  border: 1px solid var(--ns-border);
  border-radius: var(--ns-radius);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 8px 32px rgba(0, 0, 10, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.ns-btn {
  pointer-events: auto;
  padding: 0.65em 1.6em;
  border-radius: 10px;
  border: 1px solid var(--ns-border);
  background: rgba(20, 28, 54, 0.55);
  color: var(--ns-text);
  font-size: clamp(0.8rem, 1.6vw, 1rem);
  letter-spacing: 0.08em;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.ns-btn:hover { transform: translateY(-1px); background: rgba(34, 211, 238, 0.14); }
.ns-btn:active { transform: translateY(0); }
.ns-btn-primary {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.35), rgba(168, 85, 247, 0.35));
  border-color: rgba(160, 230, 255, 0.55);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.25);
}
.ns-btn-ghost { background: transparent; opacity: 0.75; }
.ns-btn-ghost:hover { opacity: 1; }

/* ---------- HUD ---------- */

.ns-hud {
  position: absolute;
  inset: 0;
  padding: calc(14px + var(--ns-safe-t)) calc(14px + var(--ns-safe-r)) calc(14px + var(--ns-safe-b)) calc(14px + var(--ns-safe-l));
  display: flex;
  flex-direction: column;
  transition: opacity 0.35s ease;
}
.ns-hud.ns-hidden { opacity: 0; pointer-events: none; }

.ns-hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}
/* Top-center is left empty on purpose: pieces spawn there and a HUD panel
   over it would hide the spawn the instant a piece appears (SPEC-RENDER §19). */
.ns-hud-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.ns-hud-col-left { align-items: flex-start; }
.ns-hud-col-right { align-items: flex-end; }

.ns-panel { padding: 10px 12px; pointer-events: auto; }
.ns-panel-label {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  color: var(--ns-text-dim);
  margin-bottom: 4px;
  text-align: center;
}

.ns-hold { width: clamp(64px, 10vw, 96px); }
.ns-hold.ns-locked .ns-preview-canvas { opacity: 0.35; filter: grayscale(1); }
.ns-preview-canvas {
  width: 100%;
  aspect-ratio: 1.3 / 1;
  display: block;
}

.ns-next { width: clamp(64px, 10vw, 96px); }
.ns-next-list { display: flex; flex-direction: column; gap: 6px; }
.ns-preview-sm { aspect-ratio: 1.3 / 1; }

.ns-score-panel { min-width: clamp(120px, 18vw, 180px); text-align: center; }
.ns-stat-label { display: block; font-size: 0.62rem; letter-spacing: 0.16em; color: var(--ns-text-dim); }
.ns-stat-value {
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  font-weight: 700;
  color: var(--ns-cyan);
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.55);
  font-variant-numeric: tabular-nums;
}
.ns-meta-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: clamp(96px, 14vw, 130px);
}
.ns-stat-small {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: clamp(0.8rem, 1.8vw, 0.95rem);
  font-weight: 600;
}
.ns-stat-small .ns-stat-label { display: inline; }
.ns-combo {
  margin-top: 6px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--ns-amber);
  text-shadow: 0 0 14px rgba(245, 158, 11, 0.6);
  animation: ns-combo-pulse 0.4s ease;
}
@keyframes ns-combo-pulse { from { transform: scale(1.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.ns-icon-btn {
  pointer-events: auto;
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--ns-border);
  background: var(--ns-glass);
  color: var(--ns-text);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px);
}

.ns-swipe-layer {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  touch-action: none;
}

.ns-score-popups {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  pointer-events: none;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 4px;
}
.ns-score-popup {
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff3c4;
  text-shadow: 0 0 12px rgba(245, 200, 80, 0.8);
  opacity: 0;
  transform: translateY(10px) scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.ns-score-popup.ns-show { opacity: 1; transform: translateY(-16px) scale(1); }
.ns-score-popup.ns-quad { color: #fff6d6; font-size: 1.5rem; text-shadow: 0 0 22px rgba(255, 220, 130, 0.9); }

/* ---------- Overlays ---------- */

.ns-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  pointer-events: auto;
  background: rgba(3, 6, 16, 0.45);
  backdrop-filter: blur(6px);
  animation: ns-fade-in 0.3s ease;
  text-align: center;
  padding: 20px;
}
@keyframes ns-fade-in { from { opacity: 0; } to { opacity: 1; } }

.ns-logo {
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 0 30px rgba(34, 211, 238, 0.7), 0 0 60px rgba(168, 85, 247, 0.4);
}
.ns-logo span { color: var(--ns-cyan); }
.ns-logo small { display: block; font-size: 0.35em; letter-spacing: 0.5em; color: var(--ns-purple); }

.ns-menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(80vw, 260px); }
.ns-best-line { font-size: 0.8rem; letter-spacing: 0.1em; color: var(--ns-text-dim); }

.ns-countdown-value {
  font-size: clamp(4rem, 18vw, 9rem);
  font-weight: 800;
  color: var(--ns-cyan);
  text-shadow: 0 0 40px rgba(34, 211, 238, 0.8);
}
.ns-countdown-value.ns-pop { animation: ns-pop 0.55s cubic-bezier(.2,1.6,.4,1); }
@keyframes ns-pop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }

.ns-glass-card {
  padding: clamp(20px, 4vw, 34px) clamp(24px, 5vw, 44px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: min(84vw, 300px);
}
.ns-glass-card h2 { margin: 0 0 6px; letter-spacing: 0.12em; font-size: clamp(1.2rem, 3vw, 1.6rem); }
.ns-glass-card .ns-btn { width: 100%; }

.ns-newbest {
  color: var(--ns-amber);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-shadow: 0 0 16px rgba(245, 158, 11, 0.7);
  animation: ns-combo-pulse 0.6s ease;
}
.ns-final-score {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  color: var(--ns-cyan);
  text-shadow: 0 0 24px rgba(34, 211, 238, 0.6);
}
.ns-final-sub { color: var(--ns-text-dim); font-size: 0.85rem; margin-bottom: 8px; }

.ns-settings-card { width: min(90vw, 360px); }
.ns-slider-row, .ns-toggle-row, .ns-select-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--ns-text-dim);
  gap: 10px;
}
.ns-slider-row input[type="range"] { flex: 1; max-width: 55%; accent-color: var(--ns-cyan); }
.ns-toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ns-cyan); }

.ns-segmented { display: flex; border: 1px solid var(--ns-border); border-radius: 8px; overflow: hidden; }
.ns-segmented button {
  border: none;
  background: transparent;
  color: var(--ns-text-dim);
  padding: 5px 10px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}
.ns-segmented button.active { background: rgba(34, 211, 238, 0.25); color: #fff; }

/* ---------- Touch controls ---------- */

.ns-touch-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(10px + var(--ns-safe-l)) calc(12px + var(--ns-safe-b)) calc(10px + var(--ns-safe-r));
  pointer-events: none;
}
.ns-touch-enabled .ns-touch-controls { display: flex; }
.ns-touch-left, .ns-touch-right {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  pointer-events: auto;
}
.ns-touch-btn {
  width: 52px; height: 52px;
  border-radius: 14px;
  border: 1px solid var(--ns-border);
  background: rgba(12, 18, 38, 0.5);
  color: var(--ns-text);
  font-size: 1.1rem;
  backdrop-filter: blur(8px);
  transition: background 0.1s ease, transform 0.1s ease;
}
.ns-touch-btn.ns-active { background: rgba(34, 211, 238, 0.35); transform: scale(0.94); }
.ns-touch-drop { grid-column: span 2; width: auto; font-size: 0.75rem; letter-spacing: 0.08em; }

/* ---------- Screen flash (Effects.js) ---------- */
.ns-screen-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  mix-blend-mode: screen;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .ns-hud-col { gap: 6px; }
  .ns-hold, .ns-next { width: clamp(50px, 16vw, 74px); }
  .ns-score-panel { min-width: 0; }
  .ns-meta-panel { min-width: 0; }
}

@media (orientation: portrait) and (max-width: 640px) {
  .ns-touch-btn { width: 46px; height: 46px; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .ns-hud { padding-top: calc(6px + var(--ns-safe-t)); padding-bottom: calc(6px + var(--ns-safe-b)); }
  .ns-touch-btn { width: 40px; height: 40px; font-size: 0.9rem; }
  .ns-logo { font-size: clamp(1.6rem, 6vh, 2.6rem); }
}

@media (min-width: 1600px) {
  .ns-stat-value { font-size: 2.3rem; }
}
