/* ── Reset & variables ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:       #080808;
  --surface:  rgba(15, 15, 15, 0.85);
  --border:   rgba(255, 255, 255, 0.07);
  --text:     #e8e4dc;
  --muted:    rgba(232, 228, 220, 0.6);
  --accent:   #e8541a;
  --accent2:  #3a8ff5;
  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  /* Prevent elastic scroll bouncing on iOS which fights the canvas */
  overscroll-behavior: none;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  /* Only hide cursor on true pointer devices */
  cursor: none;
  /* Allow JS touch handlers to work without browser interference */
  touch-action: none;
}

/* ── Custom cursor (hidden on touch devices) ── */
#cursor {
  position: fixed;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -50%);
  transition: width 0.2s, height 0.2s, background 0.2s, opacity 0.2s;
  opacity: 0;            /* revealed by JS on first mousemove, so no stray dot at 0,0 */
}
#cursor-ring {
  position: fixed;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(232, 84, 26, 0.35);
  pointer-events: none;
  z-index: 999;
  transform: translate(-50%, -50%);
  transition: width 0.25s, height 0.25s, border-color 0.2s, opacity 0.2s;
  opacity: 0;
}
#cursor.visible, #cursor-ring.visible { opacity: 1; }
#cursor.attract   { background: var(--accent2); width: 12px; height: 12px; }
#cursor-ring.attract { border-color: rgba(58, 143, 245, 0.5); width: 44px; height: 44px; }

/* Hide custom cursor dot/ring on touch-primary devices */
@media (hover: none) and (pointer: coarse) {
  #cursor, #cursor-ring { display: none; }
  canvas { cursor: default; }
}

/* ── Mode bar ── */
#mode-bar {
  position: fixed;
  top: 28px; left: 50%; transform: translateX(-50%);
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
  /* Allow taps to pass through normally */
  touch-action: manipulation;
}
.mode-btn {
  background: transparent;
  border: none;
  border-radius: 100px;
  padding: 7px 22px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
  /* Minimum tap target */
  min-height: 44px;
  touch-action: manipulation;
}
.mode-btn:hover  { color: var(--text); }
.mode-btn.active { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.mode-btn .dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.2s;
}
.mode-btn.active .dot { opacity: 1; }

/* ── Panel ── */
#panel {
  position: fixed;
  bottom: 32px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
  touch-action: manipulation;
}

/* On very small screens, tighten the bottom gap */
@media (max-height: 600px) {
  #panel { bottom: 12px; padding: 12px 14px 10px; }
  #mode-bar { top: 14px; }
}

.panel-section { display: none; flex-direction: column; gap: 12px; }
.panel-section.visible { display: flex; }

/* Sliders */
.sliders-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
}

/* Single-column layout on narrow screens */
@media (max-width: 420px) {
  .sliders-grid { grid-template-columns: 1fr; }
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 72px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 2px;
  cursor: pointer;
  /* Tall touch target without changing visual size */
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-x;
}
/* Taller thumb for touch */
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}
.slider-row .val {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--accent);
  min-width: 34px;
  text-align: right;
}

/* Word input */
.word-row { display: flex; gap: 8px; }
#word-input {
  flex: 1;
  min-width: 0;          /* let the input shrink so the row never overflows at 360px */
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 9px 16px;
  font-family: 'Space Mono', monospace;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.2s;
  /* Minimum touch target height */
  min-height: 44px;
}
#word-input::placeholder { color: var(--muted); }
#word-input:focus { border-color: rgba(232, 84, 26, 0.4); }
#word-input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232, 84, 26, 0.25); }

/* Buttons */
.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-btn {
  background: #c74110;   /* --accent darkened so the white label reaches 4.5:1 */
  color: #fff;
  border: none;
  border-radius: 100px;
  padding: 9px 18px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  white-space: nowrap;
  /* Minimum tap target */
  min-height: 44px;
  touch-action: manipulation;
}
.panel-btn:hover { background: #b83b0e; transform: translateY(-1px); }
.panel-btn:active { transform: scale(0.97); }
.panel-btn.ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}
.panel-btn.ghost:hover { background: rgba(255, 255, 255, 0.13); }

/* Swatches */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.swatch {
  /* Larger visual + invisible hit-area padding for touch */
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  flex-shrink: 0;
  width: 16px; height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
  touch-action: manipulation;
}
/* Expand tap target without changing visual size */
.swatch::after {
  content: '';
  position: absolute;
  inset: -8px;
}
.swatch:hover  { transform: scale(1.2); }
.swatch.active { border-color: rgba(255, 255, 255, 0.55); }

/* ── Keyboard focus ── */
.mode-btn:focus-visible,
.panel-btn:focus-visible,
.swatch:focus-visible,
#back-link:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.slider-row input[type="range"]:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 6px;
  border-radius: 2px;
}
.mode-btn:focus:not(:focus-visible),
.panel-btn:focus:not(:focus-visible),
.swatch:focus:not(:focus-visible) { outline: none; }

/* ── Back link ── */
#back-link {
  position: fixed;
  top: 28px; left: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  z-index: 110;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
#back-link:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.18); }
/* Icon-only on narrow screens so it never collides with the centred mode bar */
@media (max-width: 640px) {
  #back-link { top: 28px; left: 12px; padding: 0 13px; }
  #back-link .back-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-height: 600px) {
  #back-link { top: 14px; }
}

/* Hint label */
.hint-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Status ── */
#status {
  position: fixed;
  right: 28px; top: 50%; transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  z-index: 100;
}

/* Hide stats on narrow screens: they sit on top of the formed word */
@media (max-width: 480px) {
  #status { display: none; }
}

.stat-line {
  font-family: 'Space Mono', monospace;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.stat-line span { color: var(--accent); }

/* ── Hint overlay ── */
#hint {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.8s;
}
#hint p {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
#hint.gone { opacity: 0; }

/* ── Title ── */
#title {
  position: fixed;
  left: 28px; top: 50%; transform: translateY(-50%);
  pointer-events: none;
  z-index: 100;
}
#title h1 {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
/* Shrink the mode bar a touch on very narrow phones */
@media (max-width: 380px) {
  .mode-btn { padding: 7px 16px; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .panel-btn:hover { transform: none; }
}
