/* ============================================================ */
/* STOP/GO Trainer — Stylesheet                                 */
/* ============================================================ */

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

:root {
  --color-bg: #1a1a2e;
  --color-bg-alt: #16213e;
  --color-bg-card: #0f3460;
  --color-primary: #e94560;
  --color-primary-hover: #ff6b81;
  --color-go: #2ecc71;
  --color-go-hover: #27ae60;
  --color-stop: #e74c3c;
  --color-stop-hover: #c0392b;
  --color-text: #eaeaea;
  --color-text-muted: #8899aa;
  --color-text-dim: #556677;
  --color-border: #2a3a5c;
  --color-success: #2ecc71;
  --color-error: #e74c3c;
  --color-warning: #f39c12;
  --color-v1: #f39c12;
  --color-vr: #3498db;
  --color-v2: #2ecc71;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --transition: 0.3s ease;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* PWA safe area support */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* --- Screen Layout ------------------------------------------ */
.screen {
  display: none;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 480px;
  padding: 24px 20px;
  margin: 0 auto;
}

/* --- Typography --------------------------------------------- */
h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--color-primary);
  text-align: center;
}

h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.subtitle {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-top: 4px;
}

/* --- Buttons ------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-family);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.btn-primary {
  background: var(--color-primary);
  color: white;
  padding: 14px 32px;
  font-size: 1.1rem;
  width: 100%;
}

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

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--color-bg-card);
  color: var(--color-text);
  padding: 12px 24px;
  font-size: 0.95rem;
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.btn-large {
  padding: 20px 32px;
  font-size: 1.4rem;
  border-radius: var(--radius-lg);
  min-height: 64px;
}

.btn-text {
  background: none;
  color: var(--color-text-muted);
  padding: 8px;
  font-size: 0.85rem;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-text:hover {
  color: var(--color-text);
}

.btn-go {
  background: var(--color-go);
  color: white;
  flex: 1;
}

.btn-go:hover:not(:disabled) {
  background: var(--color-go-hover);
}

.btn-stop {
  background: var(--color-stop);
  color: white;
  flex: 1;
}

.btn-stop:hover:not(:disabled) {
  background: var(--color-stop-hover);
}

.btn-label {
  display: block;
}

.btn-shortcut {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.8;
}

/* --- Setup Screen ------------------------------------------- */
.setup-header {
  margin-bottom: 24px;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section {
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--color-border);
}

.speed-inputs {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.speed-inputs .input-group {
  flex: 1;
}

.input-group {
  margin-bottom: 16px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.input-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 0.95rem;
  font-family: var(--font-family);
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: auto;
}

.input-group select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.input-group select option {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.input-group input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1.1rem;
  font-weight: 600;
  font-family: var(--font-family);
  transition: border-color var(--transition);
}

.input-group input[type="number"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

.unit {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-dim);
  margin-top: 4px;
}

.radio-group {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  padding: 8px 14px;
  background: var(--color-bg);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  transition: all var(--transition);
}

.radio-label:has(input:checked) {
  background: var(--color-bg-card);
  border-color: var(--color-primary);
  color: white;
}

.radio-label input[type="radio"] {
  accent-color: var(--color-primary);
}

.setup-footer {
  margin-top: 20px;
  text-align: center;
}

/* --- Game Screen -------------------------------------------- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  width: 100%;
}

#round-counter {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.gauge-container {
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--color-border);
  width: 100%;
}

#speed-gauge {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}

#speed-markers {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 4px;
}

.marker {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

#marker-100 { color: var(--color-text-dim); }
#marker-v1 { color: var(--color-v1); }
#marker-vr { color: var(--color-vr); }
#marker-v2 { color: var(--color-v2); }

#current-speed-display {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-text);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

/* --- Failure Display ---------------------------------------- */
.failure-display {
  background: var(--color-stop);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
  animation: failure-flash 0.3s ease;
  width: 100%;
}

.failure-display.hidden {
  display: none;
}

.failure-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.failure-name {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.failure-desc {
  font-size: 0.9rem;
  opacity: 0.9;
}

@keyframes failure-flash {
  0% { transform: scale(0.95); opacity: 0; }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Action Buttons ----------------------------------------- */
.action-buttons {
  display: flex;
  gap: 16px;
  width: 100%;
}

/* --- Result Screen ------------------------------------------ */
.result-header {
  text-align: center;
  margin-bottom: 24px;
}

.result-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.result-verdict {
  font-size: 1.5rem;
  font-weight: 800;
}

.result-details {
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--color-border);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.detail-value {
  font-weight: 600;
  font-size: 0.95rem;
}

.result-explanation {
  background: var(--color-bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--color-text-muted);
  border-left: 3px solid var(--color-primary);
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Summary Screen ----------------------------------------- */
.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 24px 0;
}

.stat-card {
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  border: 1px solid var(--color-border);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.summary-details {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.summary-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- History Screen ----------------------------------------- */
.history-list {
  margin: 20px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.empty-state {
  text-align: center;
  color: var(--color-text-dim);
  padding: 40px 20px;
  font-size: 0.9rem;
}

.history-item {
  background: var(--color-bg-alt);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item-date {
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.history-item-stats {
  text-align: right;
}

.history-item-accuracy {
  font-weight: 700;
  font-size: 1.1rem;
}

.history-item-time {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.history-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Responsive --------------------------------------------- */
@media (max-width: 400px) {
  .container {
    padding: 16px 12px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .speed-inputs {
    flex-direction: column;
    gap: 8px;
  }

  .btn-large {
    padding: 16px 24px;
    font-size: 1.2rem;
    min-height: 56px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .radio-group {
    flex-direction: column;
    gap: 8px;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 520px;
  }

  .btn-large {
    padding: 24px 40px;
    font-size: 1.6rem;
  }
}

/* --- Landscape mobile --------------------------------------- */
@media (max-height: 500px) and (orientation: landscape) {
  .screen.active {
    justify-content: flex-start;
    padding-top: 8px;
  }

  .container {
    padding: 8px 16px;
  }

  .setup-header {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 1.3rem;
  }

  .form-section {
    padding: 12px;
  }

  .gauge-container {
    padding: 8px;
    margin-bottom: 8px;
  }

  #current-speed-display {
    font-size: 1.4rem;
  }

  .btn-large {
    padding: 12px 20px;
    font-size: 1.1rem;
    min-height: 44px;
  }
}

/* --- Scrollbar styling -------------------------------------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

/* --- Selection ---------------------------------------------- */
::selection {
  background: var(--color-primary);
  color: white;
}