:root {
  --primary: #4a90d9;
  --primary-dark: #3570b0;
  --success: #4caf50;
  --success-bg: #e8f5e9;
  --error: #e53935;
  --error-bg: #ffebee;
  --warning: #ff9800;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #212121;
  --text-secondary: #757575;
  --border: #e0e0e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --max-width: 600px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #e0e0e0;
    --text-secondary: #aaa;
    --border: #333;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
    --success-bg: #1b3a1b;
    --error-bg: #3a1b1b;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.hidden { display: none !important; }

.view { display: none; }
.view.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal:not(.hidden) .modal-overlay {
  animation: fadeIn 0.2s ease-out;
}

.modal:not(.hidden) .modal-body {
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  min-height: 44px;
  min-width: 44px;
  font-family: var(--font);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { font-size: 13px; padding: 8px 16px; min-height: 36px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-back {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dashboard */
.app-header {
  text-align: center;
  padding: 24px 0 20px;
}
.app-header h1 {
  font-size: 28px;
  font-weight: 700;
}
.subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 4px;
}

.tense-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tense-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}
.tense-card:active { transform: scale(0.97); }
.tense-card:hover { box-shadow: var(--shadow-lg); }
.tense-card.theory-card { border-color: var(--warning); }

.tense-card-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.2;
}
.tense-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.tense-card-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.3s;
}

.app-footer {
  text-align: center;
  padding: 24px 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.modal-body {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: var(--max-width);
  text-align: center;
}
.modal-body h3 {
  font-size: 20px;
  margin-bottom: 4px;
}
.modal-body p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Exercise */
.exercise-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
}
.exercise-info h2 { font-size: 18px; }
.progress-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.exercise-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.exercise-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.verb-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.sentence {
  font-size: 20px;
  line-height: 1.5;
  margin-bottom: 20px;
  font-weight: 500;
}

.input-row {
  display: flex;
  gap: 8px;
}

.exercise-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
}
.exercise-input:focus { border-color: var(--primary); }
.exercise-input.correct { border-color: var(--success); background: var(--success-bg); }
.exercise-input.incorrect { border-color: var(--error); background: var(--error-bg); }

.feedback {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
}
.feedback.correct {
  background: var(--success-bg);
  color: var(--success);
}
.feedback.incorrect {
  background: var(--error-bg);
  color: var(--error);
}

.char-bar {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.char-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  font-family: var(--font);
}
.char-btn:active { background: var(--border); }

.exercise-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* End screen */
.exercise-end {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-top: 20px;
}
.exercise-end h2 { margin-bottom: 16px; }
.end-stats {
  margin-bottom: 24px;
  font-size: 18px;
  line-height: 2;
}
.end-stats .score-correct { color: var(--success); font-weight: 700; }
.end-stats .score-incorrect { color: var(--error); font-weight: 700; }
.end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Reference */
.reference-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
}
.reference-header h2 { font-size: 20px; }

.reference-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 32px;
}

.ref-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.ref-section h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--primary);
}
.ref-section h4 {
  font-size: 14px;
  margin: 12px 0 6px;
  color: var(--text-secondary);
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.ref-table th, .ref-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.ref-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
}
.ref-table tr:last-child td { border-bottom: none; }

.ref-note {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 8px 0;
}

.theory-block {
  line-height: 1.7;
  font-size: 15px;
}
.theory-block p { margin-bottom: 12px; }
.theory-example {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 8px 0 16px;
}
.theory-example .original {
  font-weight: 600;
  margin-bottom: 8px;
}
.theory-example .transform {
  padding: 4px 0;
  font-size: 14px;
}
.theory-example .tense-label {
  font-weight: 600;
  color: var(--primary);
  display: inline-block;
  min-width: 160px;
}
.theory-example .transform-translation {
  color: var(--text-secondary);
  font-size: 13px;
}

.ref-reset {
  text-align: center;
  padding-top: 8px;
}

/* Responsive */
@media (min-width: 480px) {
  .tense-grid { gap: 16px; }
  .tense-card { padding: 20px; }
  .exercise-card { padding: 32px 28px; }
}

@media (max-width: 360px) {
  .tense-grid { grid-template-columns: 1fr; }
  .sentence { font-size: 18px; }
}
