:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --card-border: rgba(63, 92, 138, 0.10);
  --text: #1a2b40;
  --muted: #7a8da0;
  --accent: #247bff;
  --accent-deep: #1353c7;
  --accent-soft: rgba(36, 123, 255, 0.10);
  --success: #23a46f;
  --success-soft: rgba(35, 164, 111, 0.12);
  --danger: #d94b63;
  --danger-soft: rgba(217, 75, 99, 0.12);
  --shadow-sm: 0 2px 8px rgba(23, 50, 77, 0.06);
  --shadow: 0 8px 24px rgba(23, 50, 77, 0.07);
  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 0 12px 24px;
}

/* ── Hero bar ── */

.hero-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.hero-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hero-logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent-deep);
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.hero-right {
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: rgba(23, 50, 77, 0.07);
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.icon-button:hover {
  background: rgba(23, 50, 77, 0.12);
}

/* ── Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-dialog {
  width: min(100%, 440px);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 0;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(23, 50, 77, 0.07);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.modal-body {
  padding: 14px 18px 20px;
}

.help-text {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}

.help-list {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.help-version {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Cards ── */

.scenario-card,
.statement-card,
.status-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.scenario-card {
  margin-top: 6px;
  padding: 14px 16px;
}

.statement-card,
.status-card {
  margin-top: 10px;
  padding: 14px 16px;
}

/* ── Scenario ── */

.scenario-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.scenario-chip,
.progress-chip,
.statement-summary {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
}

.scenario-chip {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.progress-chip,
.statement-summary {
  background: rgba(23, 50, 77, 0.06);
  color: var(--text);
}

.scenario-title {
  margin: 8px 0 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

/* ── Tabs ── */

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.tab-button {
  border: 0;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  background: rgba(23, 50, 77, 0.05);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.tab-button.active {
  background: linear-gradient(135deg, var(--accent), #69a7ff);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(36, 123, 255, 0.2);
}

/* ── Statement ── */

.statement-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.statement-kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.statement-title {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 800;
}

.statement-summary {
  white-space: nowrap;
  font-size: 11px;
  flex-shrink: 0;
}

.statement-section + .statement-section {
  margin-top: 14px;
}

.statement-columns .statement-section + .statement-section {
  margin-top: 0;
}

.section-label {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.section-box {
  padding: 8px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(238, 242, 247, 0.6), rgba(255, 255, 255, 0.96));
  border: 1px solid rgba(63, 92, 138, 0.06);
  overflow: hidden;
}

.items-grid {
  display: grid;
  gap: 6px;
}

/* ── Line items ── */

.line-item {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid rgba(63, 92, 138, 0.06);
  transition: border-color 0.15s, background 0.15s;
}

.line-item.success {
  border-color: rgba(35, 164, 111, 0.3);
  background: linear-gradient(180deg, var(--success-soft), rgba(255, 255, 255, 0.95));
}

.line-item.error {
  border-color: rgba(217, 75, 99, 0.3);
  background: linear-gradient(180deg, var(--danger-soft), rgba(255, 255, 255, 0.95));
}

.article-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.article-name {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  min-width: 0;
}

.article-meta-line {
  margin: 3px 0 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}

.article-amount {
  color: var(--text);
  font-weight: 700;
}

.article-change {
  color: var(--muted);
}

.button-group {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.direction-button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 7px;
  background: rgba(23, 50, 77, 0.07);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.direction-button.selected {
  background: var(--accent);
  color: #ffffff;
}

.direction-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ── Total row ── */

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(63, 92, 138, 0.1);
}

.total-label {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.total-value {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

/* ── Status & actions ── */

.status-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 247, 252, 0.98)),
    var(--card);
}

.status-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}

.primary-button {
  flex: 1 1 0;
  background: linear-gradient(135deg, var(--accent), #69a7ff);
  color: #ffffff;
}

.secondary-button {
  flex: 1 1 0;
  background: rgba(23, 50, 77, 0.08);
  color: var(--text);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.restart-button {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid rgba(35, 164, 111, 0.25);
  border-radius: 12px;
  background: rgba(35, 164, 111, 0.08);
  color: var(--success);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s;
}

.restart-button:hover {
  background: rgba(35, 164, 111, 0.16);
}

.restart-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* ── Settings controls ── */

.scenario-controls {
  display: grid;
  gap: 12px;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field[hidden] {
  display: none;
}

.control-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.control-select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(63, 92, 138, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
}

.control-input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(63, 92, 138, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
}

.control-input::placeholder {
  color: var(--muted);
  font-weight: 600;
}

.controls-note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── Empty state ── */

.empty-state {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(23, 50, 77, 0.03);
  color: var(--muted);
  font-size: 13px;
}

/* ── Score bar (new feature) ── */

.score-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-sm);
}

.score-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
}

.score-label {
  color: var(--muted);
  font-weight: 600;
}

.score-value {
  font-weight: 800;
}

.score-correct {
  color: var(--success);
}

.score-errors {
  color: var(--danger);
}

/* ── Desktop ── */

@media (min-width: 700px) {
  .app-shell {
    padding: 0 24px 32px;
  }

  .statement-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .modal-overlay {
    align-items: center;
  }
}

@media (hover: hover) {
  .tab-button:hover {
    background: rgba(23, 50, 77, 0.1);
  }

  .tab-button.active:hover {
    background: linear-gradient(135deg, var(--accent), #69a7ff);
  }

  .primary-button:hover,
  .secondary-button:hover {
    transform: translateY(-1px);
  }
}