/* === Base Reset & Variables === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --sidebar-bg: #16213e;
  --accent: #0f3460;
  --text: #e0e0e0;
  --text-dim: #a0a0b0;
  --border: #2a2a4e;
  --btn-primary: #0f3460;
  --btn-primary-hover: #1a4a80;
  --input-bg: #1a1a2e;
  --input-border: #3a3a5e;
  --zone-1: #8B0000;
  --zone-2: #DC143C;
  --zone-3: #FF8C00;
  --zone-4: #FFD700;
  --zone-5: #90EE90;
  --zone-6: #228B22;
  --zone-7: #DAA520;
  --player-bg: #0d1b2a;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
}

/* === App Layout === */
#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "sidebar canvas"
    "player  player";
  height: 100vh;
  width: 100vw;
}

/* === Sidebar === */
#sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  padding: 20px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

/* === Controls === */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
}

.control-row {
  display: flex;
  gap: 10px;
}

.control-group.half {
  flex: 1;
}

select,
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 16px; /* Prevents zoom on iOS */
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%23e0e0e0'%3E%3Cpath d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

select:focus,
input[type="number"]:focus {
  border-color: var(--btn-primary-hover);
}

/* === Regime Description === */
.regime-desc {
  background: rgba(15, 52, 96, 0.3);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  min-height: 60px;
  max-height: 120px;
  overflow-y: auto;
  flex-shrink: 0;
  transition: opacity 0.3s;
}

.regime-desc .regime-params {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0.8;
}

/* === Primary Button === */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--btn-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 44px;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

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

/* === Queue Status === */
.queue-status {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  word-break: break-all;
  overflow-wrap: anywhere;
  min-height: 20px;
}

/* === Effort Impact === */
.effort-impact {
  background: rgba(15, 52, 96, 0.3);
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.effort-impact.hidden {
  display: none;
}

.effort-impact h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}

.effort-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 3px 0;
}

.effort-row.highlight {
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 6px;
}

.effort-value {
  font-weight: 600;
  color: var(--text);
}

.effort-row.highlight .effort-value {
  color: #90EE90;
}

/* === Legend === */
.legend {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.legend h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 2px 0;
}

.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* === Canvas Area === */
#canvas-area {
  grid-area: canvas;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

#canvas-wrapper {
  position: relative;
  width: min(100%, calc(100vh - 120px));
  max-width: 700px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

#circle-canvas {
  width: 100%;
  height: 100%;
  border-radius: 8px;
}

/* === Loading Overlay === */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.85);
  border-radius: 8px;
  z-index: 10;
  transition: opacity 0.3s;
}

#loading-overlay.hidden {
  display: none;
}

#loading-text {
  margin-top: 16px;
  font-size: 1rem;
  color: var(--text-dim);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top: 4px solid var(--btn-primary-hover);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Player Bar === */
#player-bar {
  grid-area: player;
  background: var(--player-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 8px 20px;
  gap: 16px;
  min-height: 56px;
  flex-wrap: wrap;
}

.player-controls {
  display: flex;
  gap: 6px;
}

.player-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.player-btn:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.player-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.player-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.player-speed input[type="range"] {
  width: 100px;
  accent-color: var(--btn-primary-hover);
  cursor: pointer;
}

.player-info {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

.player-stats {
  display: flex;
  gap: 14px;
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-left: auto;
  flex-wrap: wrap;
}

.player-stats span {
  white-space: nowrap;
}

/* === Mobile Layout === */
@media (max-width: 768px) {
  html, body {
    overflow: auto;
  }

  #app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  /* Canvas first */
  #canvas-area {
    order: 1;
    padding: 10px;
    flex-shrink: 0;
  }

  #canvas-wrapper {
    max-width: 100%;
    width: 100%;
  }

  /* Player right after canvas */
  #player-bar {
    order: 2;
    padding: 8px 10px;
    gap: 8px;
    min-height: 50px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .player-speed {
    order: 10;
    width: 100%;
  }

  .player-speed input[type="range"] {
    flex: 1;
  }

  .player-stats {
    order: 9;
    width: 100%;
    justify-content: space-around;
    margin-left: 0;
    gap: 8px;
    font-size: 0.75rem;
  }

  .player-info {
    font-size: 0.85rem;
  }

  /* Sidebar below — scrollable with all controls */
  #sidebar {
    order: 3;
    border-right: none;
    padding: 14px;
    max-height: none;
    overflow-y: visible;
  }

  .sidebar-title {
    font-size: 1.1rem;
  }

  .legend {
    display: none;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  #sidebar {
    padding: 10px 12px;
    gap: 8px;
  }

  .regime-desc {
    font-size: 0.8rem;
    padding: 8px 10px;
  }

  .btn-primary {
    padding: 10px;
  }
}
