:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-strong: #eef4f0;
  --ink: #17201b;
  --muted: #66746d;
  --line: #dce5df;
  --accent: #116a59;
  --accent-strong: #0b4e42;
  --accent-soft: #dff1ec;
  --danger: #b4332b;
  --shadow: 0 18px 40px rgba(28, 45, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Yu Gothic UI", "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui,
    sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfdfb;
}

.brand,
.topbar,
.panel-header,
.editor-head,
.solve-head,
.question-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand h1,
.topbar h2,
.panel-header h2,
.editor-head h3,
.solve-head h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.topbar {
  min-height: 68px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.library-panel,
.quiz-panel {
  padding: 16px;
}

.solve-panel,
.editor-panel {
  min-height: calc(100vh - 134px);
  padding: 22px;
}

.panel-header {
  margin-bottom: 14px;
}

.subject-list,
.quiz-list,
.question-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.subject-item,
.quiz-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.subject-select,
.quiz-select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
}

.subject-item.active,
.quiz-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.primary,
.secondary,
.icon-button,
.mini-button {
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
}

.primary {
  padding: 10px 14px;
  background: var(--accent);
  color: white;
}

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

.secondary {
  padding: 10px 14px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
}

.small {
  padding: 8px 12px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  background: var(--accent);
  color: white;
  font-size: 24px;
  line-height: 1;
}

.mini-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
}

.mini-button.danger {
  color: var(--danger);
}

.item-actions,
.question-tools,
.solve-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.solve-mode .manage-action {
  display: none;
}

.hidden {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 190px);
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--ink);
}

.empty-state p {
  max-width: 430px;
  margin: 0;
  line-height: 1.7;
}

.solve-view {
  display: grid;
  gap: 22px;
  max-width: 820px;
  margin: 0 auto;
}

.solve-head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.solve-question {
  display: grid;
  gap: 18px;
}

.runner-prompt {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.6;
  white-space: pre-wrap;
}

.runner-options {
  display: grid;
  gap: 12px;
}

.runner-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.runner-option input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
}

.solve-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.feedback {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
  line-height: 1.7;
  white-space: pre-wrap;
}

.feedback.correct {
  border: 1px solid var(--accent);
}

.feedback.incorrect {
  border: 1px solid var(--danger);
}

.result-view {
  display: grid;
  gap: 18px;
}

.score-box {
  display: grid;
  gap: 4px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  text-align: center;
}

.score-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.score-box strong {
  font-size: 42px;
  line-height: 1;
}

.score-box p {
  margin: 0;
  color: var(--muted);
}

.review-list {
  display: grid;
  gap: 10px;
}

.review-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.review-item h4 {
  margin: 0;
  line-height: 1.6;
  white-space: pre-wrap;
}

.review-answer {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
  line-height: 1.6;
  white-space: pre-wrap;
}

.editor-view {
  display: grid;
  gap: 16px;
}

.question-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.question-card.dragging {
  opacity: 0.55;
}

.drag-handle {
  color: var(--muted);
  user-select: none;
}

.question-toolbar {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.choice-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.choice-editor {
  display: grid;
  gap: 8px;
}

.choice-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.choice-row input[type="checkbox"],
.choice-row input[type="radio"] {
  width: 18px;
  height: 18px;
}

.add-choice {
  justify-self: start;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(14, 24, 19, 0.42);
}

.dialog-card {
  display: grid;
  gap: 18px;
  width: min(92vw, 460px);
  margin: 0;
  padding: 22px;
}

.dialog-card h3 {
  margin: 0;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .solve-panel,
  .editor-panel {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .workspace {
    padding: 16px;
  }

  .topbar,
  .editor-head,
  .solve-head {
    align-items: stretch;
    flex-direction: column;
  }

  .solve-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .question-toolbar {
    display: grid;
    grid-template-columns: auto 1fr;
  }

  .question-tools {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .runner-prompt {
    font-size: 20px;
  }
}
