:root {
  --bg: #e7ece8;
  --panel: #ffffff;
  --grid: #cfd7d2;
  --grid-dark: #aeb9b2;
  --text: #1f2923;
  --muted: #65736a;
  --excel: #217346;
  --excel-dark: #185c37;
  --excel-soft: #e7f2eb;
  --row-hover: #f4f8f5;
  --wrong: #9b2f2f;
  --wrong-soft: #f8e7e7;
  --correct: #176b3a;
  --correct-soft: #e3f3e8;
  --shadow: 0 12px 35px rgba(28, 53, 39, 0.12);
}

* { box-sizing: border-box; }
html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,.55)),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(78,104,88,.06) 27px 28px),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

button { font: inherit; }

.workbook {
  width: min(1080px, calc(100% - 32px));
  margin: 24px auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--grid-dark);
  box-shadow: var(--shadow);
}

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 70px;
  padding: 12px 18px;
  background: var(--excel-dark);
  color: white;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.12);
  font-weight: 700;
  letter-spacing: .04em;
}
.brand div { display: grid; gap: 2px; }
.brand strong { font-size: 17px; letter-spacing: .01em; }
.brand span:not(.brand-mark) { font-size: 12px; opacity: .78; }

.app-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: .9; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ee6b8;
  box-shadow: 0 0 0 3px rgba(158,230,184,.16);
}

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  min-height: 56px;
  padding: 10px 14px 0;
  background: #f5f6f5;
  border-bottom: 1px solid var(--grid-dark);
}
.file-label { align-self: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.sheet-tab {
  min-width: 130px;
  padding: 10px 14px 9px;
  border: 1px solid var(--grid);
  border-bottom: 0;
  background: white;
  color: var(--excel-dark);
  box-shadow: inset 0 3px 0 var(--excel);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.formula-bar {
  display: grid;
  grid-template-columns: 70px 42px 1fr;
  min-height: 38px;
  background: #fbfcfb;
  border-bottom: 1px solid var(--grid-dark);
  color: #536057;
  font-size: 13px;
}
.formula-bar > span {
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-right: 1px solid var(--grid);
}
.name-box, .fx { justify-content: center; }
.fx { font-style: italic; font-weight: 700; }
.formula-text { overflow: hidden; font-family: Consolas, "Courier New", monospace; white-space: nowrap; text-overflow: ellipsis; }

.sheet-stage { padding: 20px; background: #eef2ef; }
.sheet { background: white; border: 1px solid var(--grid-dark); }

.sheet-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--grid-dark);
}
.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--excel);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.sheet-heading h1 { margin: 0; font-size: clamp(21px, 3vw, 30px); line-height: 1.15; }
.sheet-meta { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.sheet-meta span {
  padding: 6px 9px;
  border: 1px solid var(--grid);
  background: #f5f7f5;
  color: var(--muted);
  font-size: 11px;
}

.grid-header, .question-row { display: grid; grid-template-columns: 62px minmax(0, 1fr) 160px; }
.grid-header {
  min-height: 34px;
  background: #e9edea;
  border-bottom: 1px solid var(--grid-dark);
  color: #4b574f;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.grid-header div { display: flex; align-items: center; padding: 0 11px; border-right: 1px solid var(--grid-dark); }
.grid-header div:last-child { border-right: 0; }

.question-row { min-height: 420px; background: white; }
.cell { min-width: 0; border-right: 1px solid var(--grid); }
.cell:last-child { border-right: 0; }
.number-cell {
  display: grid;
  place-items: start center;
  padding: 24px 6px;
  background: #f1f4f2;
  color: #68756d;
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
}
.question-cell { padding: 30px clamp(20px, 5vw, 54px) 34px; }
.category {
  margin-bottom: 9px;
  color: var(--excel);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.question-cell h2 { margin: 0 0 26px; font-size: clamp(22px, 3.5vw, 34px); line-height: 1.25; }

.options { display: grid; gap: 11px; }
.option-button {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--grid-dark);
  background: white;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.option-button:hover:not(:disabled) { border-color: var(--excel); background: #f7faf8; transform: translateY(-1px); }
.option-button:focus-visible { outline: 3px solid rgba(33,115,70,.28); outline-offset: 2px; }
.option-button:disabled { cursor: default; }
.option-letter {
  display: grid;
  align-self: stretch;
  place-items: center;
  border-right: 1px solid var(--grid);
  background: #eef2ef;
  color: #4e5b52;
  font-weight: 700;
}
.option-text { padding: 14px 16px; font-size: 16px; }
.option-button.is-correct { border-color: var(--correct); background: var(--correct-soft); }
.option-button.is-correct .option-letter { border-color: var(--correct); background: var(--correct); color: white; }
.option-button.is-wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.option-button.is-wrong .option-letter { border-color: var(--wrong); background: var(--wrong); color: white; }

.feedback {
  margin-top: 20px;
  padding: 14px 16px;
  border-left: 4px solid var(--excel);
  background: var(--excel-soft);
  line-height: 1.55;
}
.feedback strong { display: block; margin-bottom: 3px; }

.action-cell { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding: 24px 16px; background: #fafbfa; }
.status-box {
  padding: 9px 10px;
  border: 1px solid var(--grid);
  background: #f0f3f1;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-correct { border-color: #9fc9ae; background: var(--correct-soft); color: var(--correct); }
.status-wrong { border-color: #d4a3a3; background: var(--wrong-soft); color: var(--wrong); }
.next-button, .restart-button {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--excel-dark);
  background: var(--excel);
  color: white;
  cursor: pointer;
  font-weight: 700;
}
.next-button:hover, .restart-button:hover { background: var(--excel-dark); }
.next-button:focus-visible, .restart-button:focus-visible { outline: 3px solid rgba(33,115,70,.28); outline-offset: 2px; }

.result-panel { min-height: 420px; padding: 65px 24px; text-align: center; }
.result-label { display: block; margin-bottom: 12px; color: var(--excel); font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.result-panel strong { display: block; font-size: clamp(30px, 6vw, 58px); line-height: 1.1; }
.result-panel p { max-width: 570px; margin: 18px auto 26px; color: var(--muted); font-size: 17px; line-height: 1.55; }
.restart-button { min-width: 190px; }

.sheet-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--grid-dark);
  background: #f1f4f2;
  color: var(--muted);
  font-size: 11px;
}

.noscript {
  width: min(1080px, calc(100% - 32px));
  margin: 16px auto;
  padding: 14px;
  border: 1px solid #d4a3a3;
  background: var(--wrong-soft);
  color: var(--wrong);
}

[hidden] { display: none !important; }

@media (max-width: 720px) {
  body {
    min-width: 0;
    background: #eef2ef;
    font-size: 16px;
  }

  .workbook {
    width: 100%;
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  .appbar {
    min-height: 62px;
    padding: 10px 14px;
  }

  .brand {
    min-width: 0;
  }

  .brand-mark {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
  }

  .brand div {
    min-width: 0;
  }

  .brand strong,
  .brand span:not(.brand-mark) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .app-status,
  .file-label {
    display: none;
  }

  .toolbar {
    min-height: 48px;
    padding: 8px 10px 0;
    justify-content: flex-end;
  }

  .sheet-tab {
    min-width: 140px;
    padding: 10px 14px 9px;
  }

  .formula-bar {
    grid-template-columns: 52px 38px minmax(0, 1fr);
    min-height: 36px;
  }

  .formula-bar > span {
    padding: 0 8px;
  }

  .sheet-stage {
    padding: 8px;
  }

  .sheet {
    border-color: var(--grid);
  }

  .sheet-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 18px 16px 15px;
  }

  .sheet-heading h1 {
    font-size: 24px;
  }

  .sheet-meta {
    width: 100%;
    justify-content: flex-start;
  }

  .sheet-meta span {
    flex: 1 1 auto;
    text-align: center;
  }

  .grid-header {
    display: none;
  }

  .question-row {
    display: block;
    min-height: 0;
  }

  .number-cell {
    display: inline-flex;
    place-items: unset;
    margin: 14px 16px 0;
    padding: 5px 8px;
    border: 1px solid var(--grid);
    border-radius: 3px;
    background: #f1f4f2;
  }

  .question-cell {
    padding: 16px 16px 20px;
    border-right: 0;
  }

  .question-cell h2 {
    margin-bottom: 20px;
    font-size: 24px;
    line-height: 1.28;
  }

  .options {
    gap: 10px;
  }

  .option-button {
    grid-template-columns: 44px minmax(0, 1fr);
    min-height: 60px;
    border-radius: 3px;
    touch-action: manipulation;
  }

  .option-button:hover:not(:disabled) {
    transform: none;
  }

  .option-text {
    padding: 15px 14px;
    font-size: 16px;
    line-height: 1.35;
  }

  .feedback {
    margin-top: 16px;
    padding: 13px 14px;
  }

  .action-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--grid);
    border-right: 0;
  }

  .status-box,
  .next-button {
    width: 100%;
    min-height: 46px;
  }

  .result-panel {
    min-height: 0;
    padding: 52px 18px;
  }

  .result-panel strong {
    font-size: 38px;
  }

  .result-panel p {
    font-size: 16px;
  }

  .restart-button {
    width: 100%;
    min-height: 48px;
  }

  .sheet-footer {
    flex-direction: column;
    gap: 5px;
    padding: 11px 14px;
    line-height: 1.4;
  }

  .noscript {
    width: calc(100% - 16px);
    margin: 8px;
  }
}

@media (max-width: 460px) {
  .appbar {
    padding: 9px 12px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand strong {
    font-size: 16px;
  }

  .brand span:not(.brand-mark) {
    font-size: 11px;
  }

  .formula-bar {
    grid-template-columns: 46px 34px minmax(0, 1fr);
    font-size: 12px;
  }

  .sheet-stage {
    padding: 6px;
  }

  .sheet-heading {
    padding: 16px 14px 14px;
  }

  .sheet-heading h1 {
    font-size: 22px;
  }

  .number-cell {
    margin-left: 14px;
  }

  .question-cell {
    padding: 14px 14px 18px;
  }

  .question-cell h2 {
    font-size: 22px;
  }

  .option-button {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .option-text {
    padding: 14px 12px;
    font-size: 15px;
  }

  .action-cell {
    padding: 12px 14px 14px;
  }
}
