:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #697586;
  --line: #d7dde5;
  --line-strong: #aeb8c6;
  --field: #f8fafc;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok-bg: #ecfdf3;
  --ok-line: #6fcf97;
  --bad-bg: #fff1f0;
  --bad-line: #f04438;
  --fixed-bg: #f3f5f8;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "YuGothic",
    sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

.app {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.35rem);
  line-height: 1.2;
}

h2 {
  font-size: 1.05rem;
}

.tabs {
  display: inline-flex;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 3px;
}

.tab-button {
  min-width: 92px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 14px;
  font-weight: 700;
}

.tab-button.is-active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 5px rgba(15, 23, 42, 0.12);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.status-text {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.settings-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 12px;
}

.number-field {
  display: grid;
  min-width: 150px;
  gap: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.number-field input {
  width: 150px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 7px 10px;
  font-weight: 700;
}

.number-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  outline: 0;
}

.settings-panel .status-text {
  margin-bottom: 8px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  padding: 9px 16px;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

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

.secondary-button {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:hover {
  background: var(--field);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  table-layout: fixed;
}

.editor-table {
  min-width: 960px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  background: #f8fafc;
  color: #4b5565;
  font-size: 0.86rem;
  font-weight: 800;
}

.quiz-table th:first-child,
.quiz-table td:first-child {
  width: 18%;
}

.quiz-table th:nth-child(2),
.quiz-table td:nth-child(2) {
  width: 47%;
}

.quiz-table th:nth-child(3),
.quiz-table td:nth-child(3) {
  width: 35%;
}

.editor-table th:first-child,
.editor-table td:first-child {
  width: 14%;
}

.editor-table th:nth-child(2),
.editor-table td:nth-child(2) {
  width: 35%;
}

.editor-table th:nth-child(3),
.editor-table td:nth-child(3) {
  width: 30%;
}

.editor-table th:nth-child(4),
.editor-table td:nth-child(4) {
  width: 21%;
}

.fixed-answer {
  display: flex;
  min-height: 40px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--fixed-bg);
  color: #364152;
  padding: 8px 10px;
  font-weight: 700;
}

.fixed-answer.messier-value {
  gap: 6px;
}

.fixed-answer.constellation-value {
  gap: 4px;
}

.fixed-answer.messier-value .messier-prefix,
.fixed-answer.constellation-value .constellation-suffix {
  min-width: auto;
  align-self: auto;
  border-right: 0;
  border-left: 0;
  background: transparent;
  color: inherit;
}

.messier-entry,
.constellation-entry {
  display: flex;
  min-height: 40px;
  overflow: hidden;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
}

.fixed-affix-entry {
  border-color: var(--line-strong);
  background: #ffffff;
  color: #364152;
  font-weight: 700;
}

.messier-prefix,
.constellation-suffix {
  display: grid;
  flex: none;
  min-width: 36px;
  place-items: center;
  border-right: 1px solid var(--line);
  background: var(--field);
  color: var(--muted);
  font-weight: 800;
}

.constellation-suffix {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.messier-number {
  font-weight: 700;
}

.affix-value {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  background: var(--fixed-bg);
  padding: 8px 10px;
}

.answer-input,
.editor-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
}

.messier-entry .answer-input,
.messier-entry .editor-input,
.constellation-entry .answer-input,
.constellation-entry .editor-input {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.answer-input:focus,
.editor-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  outline: 0;
}

.messier-entry:focus-within,
.constellation-entry:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.messier-entry .answer-input:focus,
.messier-entry .editor-input:focus,
.constellation-entry .answer-input:focus,
.constellation-entry .editor-input:focus {
  border-color: transparent;
  box-shadow: none;
}

.answer-input.is-correct {
  border-color: var(--ok-line);
  background: var(--ok-bg);
}

.answer-input.is-wrong {
  border-color: var(--bad-line);
  background: var(--bad-bg);
}

.messier-entry.is-correct,
.constellation-entry.is-correct {
  border-color: var(--ok-line);
  background: var(--ok-bg);
}

.messier-entry.is-wrong,
.constellation-entry.is-wrong {
  border-color: var(--bad-line);
  background: var(--bad-bg);
}

.messier-entry.is-correct .answer-input,
.messier-entry.is-wrong .answer-input,
.constellation-entry.is-correct .answer-input,
.constellation-entry.is-wrong .answer-input {
  background: transparent;
}

.cell-result {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.cell-result.is-wrong {
  color: #b42318;
}

.editor-actions-cell {
  white-space: nowrap;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 6px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  background: var(--field);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.score-output {
  min-height: 28px;
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1080px);
    padding-top: 20px;
  }

  .app-header,
  .toolbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs,
  .button-row,
  .settings-panel,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .number-field,
  .number-field input {
    width: 100%;
  }

  .tab-button {
    flex: 1;
    min-width: 0;
  }
}
