:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --primary: #4361ee;
  --primary-light: #e8edfd;
  --accent: #f72585;
  --text: #1e1b4b;
  --muted: #64748b;
  --border: #e2e8f0;
  --r: 14px;
  --shadow: 0 4px 24px rgba(67, 97, 238, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #111111;
    --primary: #6ea8e0;
    --primary-light: #1a2a3c;
    --accent: #ff6ba1;
    --text: #e4e2de;
    --muted: #9a9590;
    --border: #1c1c1c;
    --shadow: 0 4px 24px rgba(110, 168, 224, 0.15);
    --overlay-bg: rgba(0, 0, 0, 0.78);
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --overlay-bg: rgba(10, 8, 35, 0.72);
  }
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Lato", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  padding-top: var(--sim-nav-offset, 44px);
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1500;
}

#result-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 1.5rem;
}

#result-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#result-card {
  background: var(--surface);
  border-radius: 28px;
  padding: clamp(1.75rem, 4vw, 3.25rem) clamp(2rem, 5vw, 4rem);
  text-align: center;
  max-width: min(92vw, 660px);
  width: 100%;
  transform: scale(0.72) translateY(40px);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.45);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(67, 97, 238, 0.1);
}

#result-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7px;
  background: linear-gradient(90deg, #f72585, #4361ee, #7209b7, #4cc9f0, #f72585);
  background-size: 200%;
  animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: 200% center;
  }
}

#result-overlay.visible #result-card {
  transform: scale(1) translateY(0);
}

#result-emoji-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  margin-bottom: 1rem;
  font-size: 3rem;
  background: var(--bg);
  transition: background 0.3s;
}

#result-label {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  margin-bottom: 0.75rem;
}

#result-text {
  font-family: "Lato", sans-serif;
  font-size: clamp(1.7rem, 4.5vw, 2.8rem);
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 1.75rem;
}

#result-close {
  background: linear-gradient(135deg, var(--primary), #7209b7);
  color: white;
  border: none;
  padding: 0.9rem 3rem;
  border-radius: 50px;
  font-size: 1.15rem;
  font-family: "Lato", sans-serif;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 18px rgba(67, 97, 238, 0.38);
}

#result-close:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 8px 26px rgba(67, 97, 238, 0.48);
}

.tabs {
  background: var(--surface);
  padding: 0.35rem 1rem;
  display: flex;
  gap: 0.4rem;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-top: 0;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.35rem 1.1rem;
  border: 2px solid transparent;
  border-radius: 50px;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.tab-btn:hover:not(.active) {
  background: var(--bg);
  color: var(--text);
}

main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tab-panel {
  display: none;
  height: 100%;
}

.tab-panel.active {
  display: flex;
  flex-direction: row;
  gap: 1.25rem;
  padding: 1rem 1.25rem;
  height: 100%;
  align-items: stretch;
}

@media (max-width: 740px) {
  .tab-panel.active {
    flex-direction: column;
    overflow-y: auto;
  }
}

.wheel-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding-bottom: 1.25rem;
}

.wheel-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 26px;
}

.wheel-pointer {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 44px solid var(--accent);
  filter: drop-shadow(0 3px 8px var(--accent));
}

canvas.wheel-canvas {
  display: block;
  border-radius: 50%;
  width: min(calc(100dvh - 145px), calc(100vw - 410px));
  height: min(calc(100dvh - 145px), calc(100vw - 410px));
  max-width: min(700px, 82vmin);
  max-height: min(700px, 82vmin);
  box-shadow: 0 0 0 8px var(--surface), 0 0 0 11px rgba(67, 97, 238, 0.18), 0 18px 52px rgba(0, 0, 0, 0.2);
}

.spin-btn {
  font-family: "Lato", sans-serif;
  font-size: clamp(1.25rem, 2.5vw, 1.7rem);
  background: linear-gradient(135deg, #f72585, #ff6b6b);
  color: white;
  border: none;
  padding: 0.75rem 3rem;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(247, 37, 133, 0.42);
  transition: transform 0.2s, box-shadow 0.2s;
  letter-spacing: 0.5px;
}

.spin-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 9px 28px rgba(247, 37, 133, 0.52);
}

.spin-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.spin-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.control-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: var(--r);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

@media (max-width: 740px) {
  canvas.wheel-canvas {
    width: min(80vw, 80vh);
    height: min(80vw, 80vh);
  }

  .control-panel {
    width: 100%;
  }
}

.panel-title {
  font-family: "Lato", sans-serif;
  font-size: 1.3rem;
  color: var(--primary);
}

.panel-desc {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.seg-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.seg-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.45;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.slider-block {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-lbl {
  font-weight: 800;
  font-size: 1rem;
}

.slider-val {
  font-family: "Lato", sans-serif;
  font-size: 2.8rem;
  color: var(--primary);
  line-height: 1;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
  height: 6px;
  border-radius: 3px;
}

.slider-hint {
  background: var(--bg);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.6;
  border: 1px solid var(--border);
}

.wheel-mgr {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.wheel-tabs-scroll {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex-wrap: wrap;
}

.wheel-tabs-scroll::-webkit-scrollbar {
  display: none;
}

.wheel-tab {
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.3rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 50px;
  cursor: pointer;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
}

.wheel-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.wheel-tab:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}

.add-wheel-btn {
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.3rem 0.9rem;
  border: 2px dashed rgba(67, 97, 238, 0.4);
  border-radius: 50px;
  cursor: pointer;
  background: transparent;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
}

.add-wheel-btn:hover {
  background: var(--primary);
  color: white;
  border-style: solid;
}

.wheel-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.wheel-name-input {
  flex: 1;
  padding: 0.4rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: "Lato", sans-serif;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.2s, background-color 0.2s;
}

.wheel-name-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.del-wheel-btn {
  padding: 0.4rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: "Lato", sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.del-wheel-btn:hover:not(:disabled) {
  border-color: #ef4444;
  color: #ef4444;
  background: #fff5f5;
}

.del-wheel-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.custom-editor {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.fields-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.field-dot {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  flex-shrink: 0;
}

.field-input {
  flex: 1;
  padding: 0.45rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: "Lato", sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.13);
  background: var(--surface);
}

.field-del {
  background: transparent;
  border: 2px solid var(--border);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  transition: all 0.15s;
  flex-shrink: 0;
}

.field-del:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: #fff5f5;
}

.add-btn {
  background: var(--primary-light);
  color: var(--primary);
  border: 2px dashed rgba(67, 97, 238, 0.38);
  border-radius: 10px;
  padding: 0.55rem;
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.2s;
}

.add-btn:hover {
  background: var(--primary);
  color: white;
  border-style: solid;
  border-color: var(--primary);
}

.save-badge {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #10b981;
  font-weight: 800;
  opacity: 0;
  height: 1.2em;
  transition: opacity 0.3s;
}

.save-badge.show {
  opacity: 1;
}

.footer-hint {
  font-size: 0.78rem;
  color: var(--text);
  opacity: 0.7;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
}

/* Timer */
#panel-timer.tab-panel.active {
  padding: 0.75rem;
}

.timer-area {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.timer-display-wrap {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: var(--timer-bg);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  --timer-split: 100%;
  --timer-bg: #ffffff;
  --timer-wall: #000000;
  --timer-text-above: #000000;
  --timer-text-below: #ffffff;
  --timer-step-bg: rgba(255, 255, 255, 0.86);
  --timer-step-border: rgba(0, 0, 0, 0.24);
  --timer-step-text: #000000;
  --timer-digit-size: clamp(3rem, 12vw, 11rem);
  --timer-colon-width: 0.36em;
}

@media (prefers-color-scheme: dark) {
  .timer-display-wrap {
    --timer-bg: #000000;
    --timer-wall: #ffffff;
    --timer-text-above: #ffffff;
    --timer-text-below: #000000;
    --timer-step-bg: rgba(0, 0, 0, 0.72);
    --timer-step-border: rgba(255, 255, 255, 0.36);
    --timer-step-text: #ffffff;
  }
}

.timer-water {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--timer-bg);
}

.timer-water-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: var(--timer-wall);
  transition: height 0.8s linear;
}

.timer-overlay-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  padding: clamp(0.8rem, 2vw, 1.4rem) clamp(0.9rem, 2.5vw, 1.8rem) clamp(1rem, 2.3vw, 1.6rem);
}

/* ── Merged display: arrows + big digits ──────────────────────────────────── */

.timer-controls-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.timer-display-row {
  display: grid;
  grid-template-columns: 2ch var(--timer-colon-width) 2ch var(--timer-colon-width) 2ch;
  align-items: baseline;
  font-family: "Lato", sans-serif;
  font-size: var(--timer-digit-size);
  font-weight: 900;
  transition: font-size 0.2s ease;
}

.timer-num {
  font-size: 1em;
  line-height: 1;
  width: 2ch;
  text-align: center;
  background-image: linear-gradient(
    to bottom,
    var(--timer-text-above) var(--timer-split),
    var(--timer-text-below) var(--timer-split)
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.timer-colon {
  font-size: 1em;
  line-height: 1;
  width: var(--timer-colon-width);
  text-align: center;
  background-image: linear-gradient(
    to bottom,
    var(--timer-text-above) var(--timer-split),
    var(--timer-text-below) var(--timer-split)
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.timer-arrows-row {
  display: grid;
  grid-template-columns: 2ch var(--timer-colon-width) 2ch var(--timer-colon-width) 2ch;
  align-items: center;
  justify-items: center;
  font-family: "Lato", sans-serif;
  font-size: var(--timer-digit-size);
  font-weight: 900;
}

.timer-colon-gap {
  display: block;
  width: var(--timer-colon-width);
}

.timer-step-btn {
  width: clamp(2rem, 4vw, 2.5rem);
  height: clamp(2rem, 4vw, 2.5rem);
  border-radius: 999px;
  border: 2px solid var(--timer-step-border);
  background: var(--timer-step-bg);
  color: var(--timer-step-text);
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background-color 0.15s;
}

.timer-step-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.timer-step-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* When running: collapse arrow rows, grow numbers, hide presets */
.timer-display-wrap.timer-running .timer-arrows-row {
  visibility: hidden;
  height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.timer-display-wrap.timer-running .timer-num,
.timer-display-wrap.timer-running .timer-colon {
  font-size: 1em;
}

.timer-display-wrap.timer-running {
  --timer-digit-size: clamp(3.8rem, 15vw, 13rem);
}

.timer-display-wrap.timer-running .timer-presets {
  display: none;
}

/* ── Presets ──────────────────────────────────────────────────────────────── */

.timer-presets {
  display: flex;
  flex-direction: column;
  width: min(100%, 650px);
}

.timer-presets-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.5rem;
}

.timer-preset-btn {
  border: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.58);
  color: #0f1f4a;
  border-radius: 11px;
  padding: 0.48rem 0.3rem;
  cursor: pointer;
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.timer-preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 255, 255, 0.82);
}

.timer-preset-btn.active {
  background: rgba(234, 242, 255, 0.88);
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Action buttons ───────────────────────────────────────────────────────── */

.timer-actions {
  display: flex;
  gap: 0.55rem;
  width: min(100%, 650px);
}

.timer-action-btn {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-family: "Lato", sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  color: #0f1f4a;
  background: rgba(255, 255, 255, 0.68);
  transition: all 0.15s;
}

.timer-action-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 255, 255, 0.9);
}

.timer-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.timer-start {
  background: #35c68b;
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(36, 166, 111, 0.33);
}

.timer-start:hover:not(:disabled) {
  border-color: transparent;
  color: #ffffff;
  filter: brightness(1.05);
}

@media (max-width: 980px) {
  .timer-presets-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 740px) {
  #panel-timer.tab-panel.active {
    padding: 0.55rem;
  }

  .timer-display-wrap {
    border-radius: 20px;
  }

  .timer-overlay-content {
    padding: 0.65rem;
    gap: 0.75rem;
  }

  .timer-num,
  .timer-colon {
    font-size: 1em;
  }

  .timer-display-wrap {
    --timer-digit-size: clamp(2.3rem, 13.5vw, 4.3rem);
  }

  .timer-display-wrap.timer-running .timer-num,
  .timer-display-wrap.timer-running .timer-colon {
    font-size: 1em;
  }

  .timer-display-wrap.timer-running {
    --timer-digit-size: clamp(2.8rem, 16vw, 5.5rem);
  }

  .timer-actions {
    width: 100%;
  }
}
