:root {
  --bg-color: #0d0d0f;
  --circle-color: #4fc3f7;
  --text-color: #ffffff;

  --chrome-bg: #1c1c1e;
  --chrome-border: #2c2c2e;
  --chrome-field: #2c2c2e;
  --chrome-field-border: #3a3a3c;
  --chrome-text: #e5e5e7;
  --chrome-muted: #9a9a9e;
  --accent: #f5a623;
  --accent-text: #1c1c1e;
  --settings-btn-color: #f5a623;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button { font-family: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
  background: var(--bg-color);
  overflow: hidden;
}

/* ---------- Stage / circle ---------- */

#stage {
  flex: 1 1 auto;
  min-height: 190px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#circle-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transition: transform 0.35s ease;
}

body.settings-open #circle-wrapper {
  transform: scale(0.72);
}

/* Fixed-size box (sized to the max circle diameter). Everything inside is
   positioned relative to this box, so it never shifts as the circle grows
   or shrinks, and so the label stays pinned in place. */
#circle-slot {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 72px; /* reserved room for the label under the circle */
}

#circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--circle-color);
  width: 100px;
  height: 100px;
  transition-property: width, height;
  transition-timing-function: ease-in-out;
}

#phase-text {
  position: absolute;
  left: 50%;
  top: 100%;
  margin-top: 24px;
  transform: translate(-50%, 0);
  white-space: nowrap;
  font-size: clamp(1.1rem, 4vw, 1.8rem);
  letter-spacing: 0.2em;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-color);
  user-select: none;
  transition: top 0.2s ease, transform 0.2s ease, margin 0.2s ease;
}

/* Text-inside-circle mode: a bit smaller and tighter so it fits the
   smallest circle size comfortably. */
#circle-wrapper.text-center #phase-text {
  top: 50%;
  margin-top: 0;
  transform: translate(-50%, -50%);
  font-size: clamp(0.8rem, 3.2vw, 1.2rem);
  letter-spacing: 0.12em;
}

/* ---------- Progress dot ---------- */
/* Position is driven from JS every frame (translate transform), so it can
   track the circle's actual current radius as it grows/shrinks, not a
   fixed track. */

#progress-orbit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}

#progress-orbit.visible {
  display: block;
}

#progress-dot {
  position: absolute;
  top: 0;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-color);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.45);
  will-change: transform;
}

/* ---------- Bottom bar ---------- */

#bottom-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
}

#speed-trim-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: var(--chrome-muted);
}

#speed-trim-slow,
#speed-trim-fast {
  width: 16px;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  user-select: none;
}

#speedTrim {
  flex: 1 1 auto;
  width: 100%;
  margin: 0;
  accent-color: var(--settings-btn-color);
}

#settingsToggle {
  flex: 0 0 auto;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  border: none;
  background: var(--chrome-field);
  color: var(--chrome-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:active { transform: scale(0.92); }

.icon-btn.accent {
  background: var(--settings-btn-color);
  color: var(--accent-text);
}

.icon-btn.small {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

/* ---------- Settings panel ---------- */

#settings-panel {
  position: relative;
  flex: 0 1 auto;
  max-height: 0;
  overflow: hidden;
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
  transition: max-height 0.35s ease;
}

#settings-panel.open {
  max-height: 58vh;
}

#settings-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px 24px;
}

#scroll-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  background: linear-gradient(to bottom, transparent, var(--chrome-bg) 70%);
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#settings-panel.has-more #scroll-hint {
  opacity: 1;
}

#scroll-hint svg {
  animation: hint-bounce 1.4s ease-in-out infinite;
}

@keyframes hint-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

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

.settings-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--chrome-text);
}

.settings-group { margin-bottom: 18px; }

.settings-caption {
  margin: 0 0 8px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chrome-muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--chrome-muted);
}

input[type="number"] {
  background: var(--chrome-field);
  border: 1px solid var(--chrome-field-border);
  color: #f2f2f2;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  width: 100%;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  border: 1px solid var(--chrome-field-border);
  border-radius: 8px;
  padding: 3px;
  background: var(--chrome-field);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }

/* Toggle switches */
.toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  font-size: 0.85rem;
  color: var(--chrome-text);
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--chrome-field-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #e5e5e7;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.switch input:checked + .slider {
  background: var(--settings-btn-color);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
  background: #1c1c1e;
}

.settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#resetDefaults {
  margin-left: auto;
}

.secondary-btn,
#resetDefaults {
  background: transparent;
  border: 1px solid var(--chrome-field-border);
  color: var(--chrome-muted);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 0.8rem;
  cursor: pointer;
}

.secondary-btn:active,
#resetDefaults:active { transform: scale(0.97); }

#about-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.62);
  z-index: 40;
}

#about-modal.hidden {
  display: none;
}

#about-card {
  width: min(560px, 100%);
  border-radius: 14px;
  border: 1px solid var(--chrome-field-border);
  background: var(--chrome-bg);
  color: var(--chrome-text);
  padding: 18px 18px 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

#about-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

#about-card p {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--chrome-text);
}

#about-card a {
  color: var(--accent);
}

.about-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(0, 0, 0, 0.86);
  color: #fff;
  border: 1px solid var(--chrome-field-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
}

#toast.hidden {
  display: none;
}

/* ---------- Landscape / tablet / laptop ---------- */

@media (min-width: 800px) {
  #app { flex-direction: row; }

  #bottom-bar {
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    width: 90px;
    border-top: none;
    border-right: 1px solid var(--chrome-border);
    padding: 22px 12px calc(22px + env(safe-area-inset-bottom));
  }

  #settings-panel {
    max-width: 0;
    max-height: none;
    height: 100%;
    overflow: hidden;
    border-top: none;
    border-left: 1px solid var(--chrome-border);
    order: 3;
  }

  #settings-panel.open {
    max-height: none;
    max-width: 380px;
  }

  #settings-scroll {
    padding: 22px 24px 28px;
  }

  .settings-grid { grid-template-columns: 1fr 1fr; }

  body.settings-open #circle-wrapper {
    transform: scale(0.85);
  }
}

@media (min-width: 800px) and (orientation: landscape) {
  #speed-trim-wrap {
    flex-direction: column;
    width: auto;
    gap: 8px;
    margin-bottom: 8px;
  }

  #speedTrim {
    width: 26px;
    height: min(42vh, 280px);
    writing-mode: vertical-lr;
    direction: rtl;
    transform: none;
  }

  #speed-trim-slow,
  #speed-trim-fast {
    width: auto;
    line-height: 1;
  }

  #speed-trim-fast { order: 1; }
  #speedTrim { order: 2; }
  #speed-trim-slow { order: 3; }
}

