/* Math Drill - PWA Styles */

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-light: #252542;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --success: #00b894;
  --error: #d63031;
  --text: #ffffff;
  --text-muted: #a0a0b0;
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh; /* Dynamic viewport height for iOS */
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

body {
  padding-bottom: 70px; /* space for bottom nav */
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  padding: 20px 16px 90px;
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Tabs */
.tab {
  display: none;
  min-height: calc(100dvh - 70px);
}

.tab.active {
  display: block;
}

.header {
  text-align: center;
  padding: 20px 0 30px;
}

.header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--surface-light);
  color: var(--text);
}

.btn-secondary:hover {
  background: #2f2f52;
}

/* Home - No Problem */
.next-notification {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.next-notification .label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.next-notification .time {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
}

/* Timer */
.timer-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
}

.timer-ring {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.timer-bg {
  fill: none;
  stroke: var(--surface-light);
  stroke-width: 8;
}

.timer-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-progress.urgent {
  stroke: var(--error);
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Problem Display */
.problem-display {
  font-size: 2.8rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  font-family: ui-monospace, 'SF Mono', monospace;
  letter-spacing: 2px;
}

/* Answer Input */
.answer-input {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--surface-light);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
  font-family: ui-monospace, monospace;
}

.answer-input:focus {
  outline: none;
  border-color: var(--accent);
}

.answer-input::placeholder {
  color: var(--text-muted);
}

/* Remove number input arrows */
.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Result Display */
.result-icon {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 12px;
}

.result-text {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}

.result-text.correct {
  color: var(--success);
}

.result-text.wrong {
  color: var(--error);
}

.correct-answer {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 1.1rem;
}

.correct-answer span {
  color: var(--success);
  font-weight: 600;
  font-family: ui-monospace, monospace;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-card:first-child,
.stat-card:nth-child(2) {
  grid-column: span 1;
}

.stat-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

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

/* History */
.history-section {
  margin-top: 24px;
}

.history-section h2 {
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.history-list {
  list-style: none;
}

.history-list li {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}

.history-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 20px !important;
}

.history-item .problem {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}

.history-item .result-icon {
  font-size: 1rem;
  margin: 0;
}

.history-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

/* Settings */
.settings-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-section h2 {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

/* Slider */
.slider-container {
  margin-bottom: 8px;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-light);
  border-radius: 3px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

/* Toggle List */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--surface-light);
  cursor: pointer;
}

.toggle-item:last-child {
  border-bottom: none;
}

.toggle-item span:first-child {
  font-size: 1rem;
}

.toggle-item input {
  display: none;
}

.toggle-switch {
  width: 51px;
  height: 31px;
  background: var(--surface-light);
  border-radius: 16px;
  position: relative;
  transition: background 0.3s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
}

.toggle-item input:checked + .toggle-switch {
  background: var(--accent);
}

.toggle-item input:checked + .toggle-switch::after {
  transform: translateX(20px);
}

/* Setting Row */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.setting-value {
  font-weight: 600;
  color: var(--accent);
}

/* Time Window */
.time-window {
  display: flex;
  gap: 16px;
  margin: 16px 0;
}

.time-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.time-row input {
  padding: 12px;
  border: 2px solid var(--surface-light);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.time-row input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Permission Status */
.permission-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--surface-light);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

#perm-icon {
  font-size: 1.5rem;
}

#perm-text {
  font-size: 0.95rem;
}

.permission-status.granted #perm-text {
  color: var(--success);
}

.permission-status.denied #perm-text {
  color: var(--error);
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  border-top: 1px solid var(--surface-light);
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  border-radius: var(--radius-sm);
}

.nav-btn.active {
  color: var(--accent);
}

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

.nav-icon {
  font-size: 1.4rem;
}

.nav-label {
  font-size: 0.75rem;
  font-weight: 500;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.3s ease-out;
}

@keyframes correctFlash {
  0%, 100% { background: var(--surface); }
  50% { background: #0d3d32; }
}

@keyframes wrongFlash {
  0%, 100% { background: var(--surface); }
  50% { background: #3d0d0d; }
}

.card.correct-flash {
  animation: correctFlash 0.5s ease-out;
}

.card.wrong-flash {
  animation: wrongFlash 0.5s ease-out;
}