:root {
  color-scheme: dark;
  font-family: "SF Pro Display", "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-scale: 1;
  --bg: #03050b;
  --panel: rgba(20, 26, 41, 0.95);
  --card: rgba(15, 19, 31, 0.95);
  --accent: #5df2c0;
  --accent-soft: rgba(93, 242, 192, 0.12);
  --missed: #ff5470;
  --correct: #48ff96;
  --text: #f3f7ff;
  --text-dim: #9aa6c8;
  --border: rgba(255, 255, 255, 0.08);
  font-size: calc(16px * var(--font-scale));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #0f1b33, #03050b);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 1vw;
  overflow: hidden;
}

.app-shell {
  width: min(520px, 92vw);
  height: min(900px, 92vh);
  background: var(--panel);
  border-radius: 28px;
  border: 1px solid var(--border);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.55);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header"
    "main"
    "footer";
  padding: 1.5rem;
  gap: 1.1rem;
  min-height: 0;
}

.app-main {
  grid-area: main;
}

.app-footer {
  grid-area: footer;
}

.app-header {
  grid-area: header;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 1rem;
  align-items: stretch;
  min-height: 0;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.branding h1 {
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  margin: 0;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sync-button {
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sync-button:hover,
.sync-button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.options {
  position: relative;
}

.options-trigger {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

.options-panel {
  position: absolute;
  top: 44px;
  right: 0;
  width: 240px;
  padding: 1rem;
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.options-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.option-row + .option-row {
  margin-top: 0.8rem;
}

.option-row.small p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.option-row label {
  flex: 1;
}

.option-row input[type="range"] {
  flex: 2;
}

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "question"
    "decision";
  grid-template-rows: 1fr auto;
  gap: 0.8rem;
  min-height: 0;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-radius: 20px;
  background: rgba(9, 13, 24, 0.75);
  border: 1px solid var(--border);
  padding: 0.75rem;
  text-align: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  width: 100%;
  justify-items: stretch;
  align-items: stretch;
}

.header-section {
  width: 100%;
}

.scoreboard div {
  min-width: 0;
}

.scoreboard strong {
  font-size: 1.4rem;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

select {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
}

.question-card {
  grid-area: question;
  flex: 1;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at top right, rgba(93, 242, 192, 0.08), rgba(12, 16, 26, 0.95));
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 0;
}

.meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.question-body {
  flex: 1;
  border-radius: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  padding: 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  overflow: auto;
}

.question-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.question-body p {
  margin: 0;
  font-size: clamp(1.1rem, 2.4vw, 1.3rem);
  line-height: 1.4;
  overflow-wrap: break-word;
}

.options-list {
  margin: 0;
  padding-left: 1.25rem;
  display: none;
  gap: 0.35rem;
  flex-direction: column;
}

.options-list.visible {
  display: flex;
}

.options-list li {
  font-size: 1rem;
}

.answer {
  border-radius: 16px;
  background: rgba(5, 255, 200, 0.08);
  border: 1px solid transparent;
  padding: 0.8rem;
  transition: opacity 0.2s ease;
  opacity: 0;
}

.answer.visible {
  opacity: 1;
  border-color: rgba(93, 242, 192, 0.5);
}

.answer p {
  margin: 0 0 0.25rem;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.answer strong {
  font-size: 1.1rem;
}

.tap-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.decision-bar {
  grid-area: decision;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
}

.decision {
  height: 56px;
  border-radius: 18px;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.decision.correct {
  background: rgba(72, 255, 150, 0.15);
  color: var(--correct);
}

.decision.missed {
  background: rgba(255, 84, 112, 0.15);
  color: var(--missed);
}

.decision.pass {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.decision:active {
  transform: scale(0.97);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4);
}

.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.app-footer p {
  margin: 0;
}

/* Editor page */
body.editor-body {
  display: block;
  align-items: stretch;
  justify-content: flex-start;
  padding: clamp(1rem, 4vw, 2.5rem);
  overflow: auto;
}

.editor-shell {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.editor-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 1.5rem;
}

.editor-header h1 {
  margin: 0 0 0.3rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
}

.editor-header p {
  margin: 0;
  color: var(--text-dim);
}

.editor-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.editor-header-actions button,
.file-picker {
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.editor-header-actions button:hover,
.editor-header-actions button:focus-visible,
.file-picker:hover,
.file-picker:focus-within {
  border-color: var(--accent);
}

.editor-header-actions .accent,
.panel-header .accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(93, 242, 192, 0.4);
}

.panel {
  background: rgba(7, 10, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.panel-header p {
  margin: 0.25rem 0 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.editor-main {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.25fr);
  gap: 1.5rem;
}

.question-list-wrapper {
  max-height: 520px;
  overflow: auto;
  padding-right: 0.3rem;
  flex: 1 1 auto;
}

.question-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.question-list-empty {
  margin: 0;
  padding: 1.25rem;
  border: 1px dashed var(--border);
  border-radius: 18px;
  color: var(--text-dim);
  text-align: center;
}

.question-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.question-filter-bar input[type="search"] {
  flex: 1 1 240px;
}

.question-filter-bar select {
  flex: 0 0 auto;
  min-width: 150px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.question-item-button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  padding: 0.9rem;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.question-item-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(93, 242, 192, 0.4);
}

.question-item-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.question-title {
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 1.5rem;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
}

.pill.subtle {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
}

.tag-chip {
  display: inline-flex;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: rgba(93, 242, 192, 0.15);
  color: var(--accent);
  font-size: 0.8rem;
  border: 1px solid rgba(93, 242, 192, 0.35);
}

.tag-chip.ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  border-color: var(--border);
}

.tag-chip.removable {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-list-empty {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.tag-editor {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.panel [hidden] {
  display: none !important;
}

.tag-input-row {
  display: flex;
  gap: 0.5rem;
}

.tag-input-row button {
  min-width: 110px;
}

input[type="text"],
textarea {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
}

textarea {
  resize: vertical;
}

label > span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.field-label small {
  color: var(--text-dim);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
}

.ghost:hover,
.ghost:focus-visible {
  border-color: var(--missed);
  color: var(--missed);
}

.editor-status {
  min-width: 140px;
  text-align: right;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.category-summary {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.category-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.category-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-count {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.category-edit {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.category-edit input {
  min-width: 160px;
}

.category-edit button {
  padding: 0.45rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.category-empty {
  margin: 0;
  color: var(--text-dim);
  text-align: center;
}

@media (max-width: 520px) {
  body {
    padding: 0;
  }

  .app-shell {
    width: 95vw;
    height: 95vh;
    border-radius: 0;
    padding: 1.25rem clamp(0.8rem, 4vw, 1.25rem);
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .decision {
    height: 52px;
  }
}

@media (max-width: 960px) {
  .editor-main {
    grid-template-columns: 1fr;
  }

  .editor-header {
    flex-direction: column;
  }

  .editor-header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .question-list-wrapper {
    max-height: none;
  }

  .question-list-panel {
    max-height: 65vh;
    overflow: hidden;
  }

  .question-list-wrapper {
    max-height: none;
    overflow-y: auto;
  }
}

@media (orientation: portrait) {
  .editor-body .editor-main {
    grid-template-columns: 1fr;
  }

  .editor-body .question-list-panel {
    max-height: 65vh;
    overflow: hidden;
  }

  .editor-body .question-list-wrapper {
    max-height: none;
    overflow-y: auto;
  }
}

@media (orientation: landscape) {
  body {
    padding: 1.5vh 2vw;
  }

  .app-shell {
    width: min(1200px, 96vw);
    height: min(640px, 90vh);
    grid-template-columns: minmax(260px, 0.34fr) minmax(0, 0.66fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "header main"
      "header main"
      "footer main";
    gap: 1rem 1.25rem;
    padding: 1.25rem;
  }

  .app-header {
    gap: 0.9rem;
    height: 100%;
  }

  .header-actions {
    justify-content: flex-end;
  }

  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "question"
      "decision";
    column-gap: 1rem;
    row-gap: 0.65rem;
  }

  .scoreboard {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .decision-bar {
    align-self: end;
  }

  .app-footer {
    align-self: end;
    text-align: left;
  }
}
