:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --paper: #f4f8fb;
  --panel: #ffffff;
  --line: #d8e2ea;
  --axis: #182736;
  --red: #e04444;
  --green: #16895f;
  --amber: #f2a51a;
  --purple: #8154cc;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.12);
  --radius: 8px;
  --touch: 48px;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  background: #eef4f8;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select {
  min-height: var(--touch);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

button {
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-weight: 800;
}

input:disabled,
select:disabled,
button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

.topbar {
  position: relative;
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #071018;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 142px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.lesson-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 6px;
  align-items: center;
  margin-bottom: 3px;
  font-size: clamp(0.72rem, 0.95vw, 0.88rem);
  line-height: 1.15;
  font-weight: 800;
  color: rgba(244, 250, 255, 0.74);
}

.lesson-breadcrumb a {
  color: #bfefff;
  text-decoration: none;
  border-bottom: 1px solid rgba(143, 216, 243, 0.45);
}

.lesson-breadcrumb a:hover,
.lesson-breadcrumb a:focus-visible {
  color: #ffffff;
  border-bottom-color: #ffffff;
  outline: none;
}

.lesson-breadcrumb span[aria-hidden="true"] {
  color: rgba(244, 250, 255, 0.48);
  font-weight: 700;
}

.title-block { min-width: 0; }

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.9rem);
  line-height: 1.05;
  font-weight: 800;
}

.top-actions {
  position: relative;
  z-index: 9;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: end;
  flex-wrap: wrap;
}

.icon-button {
  width: var(--touch);
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #122436;
  color: #ffffff;
  border-color: #263d51;
}

.icon-button:hover {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.home-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid #263d51;
  border-radius: 8px;
  background: #122436;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.toolbar {
  position: relative;
  z-index: 6;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(15, 33, 49, 0.08);
}

.toolbar-left,
.toolbar-right,
.control-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.control-label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.wide-button,
.primary-button {
  min-width: 112px;
  padding: 0 13px;
}

.primary-button {
  background: var(--blue);
  border-color: var(--blue);
  color: #06111a;
}

.tool-menu {
  position: relative;
}

.tool-menu summary {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.tool-menu summary::-webkit-details-marker { display: none; }

.menu-panel {
  position: absolute;
  left: 0;
  right: auto;
  top: calc(100% + 8px);
  width: min(360px, calc(100vw - 24px));
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.lesson-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: min(520px, 100%);
}

.lesson-tab {
  min-width: 0;
  min-height: 48px;
  padding: 0 10px;
}

.lesson-tab.is-active {
  background: #e7f6fd;
  border-color: var(--blue);
  color: #06111a;
}

.check-pill {
  min-height: 42px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-weight: 800;
}

.check-pill input {
  min-height: auto;
  width: 20px;
  height: 20px;
}

.number-box,
select {
  min-width: 92px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.workspace {
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  background: #eef4f8;
}

.tool-surface {
  position: relative;
  height: 100%;
  min-height: 520px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.board-wrap {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
  gap: 10px;
}

.canvas-shell {
  min-height: 0;
  background: #fbfdff;
  border: 2px solid #c9d8e3;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.status {
  min-height: 56px;
  display: grid;
  gap: 3px;
  align-content: center;
  padding: 8px 12px;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.side-panel {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  padding-right: 2px;
  display: grid;
  gap: 12px;
  align-content: start;
  scrollbar-gutter: stable;
}

.panel-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
}

.point-list,
.answer-list {
  display: grid;
  gap: 6px;
}

.point-row,
.answer-row {
  display: grid;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 6px 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 800;
}

.point-row { grid-template-columns: 32px minmax(0, 1fr); }

.answer-row { grid-template-columns: 68px minmax(0, 1fr); }

.point-badge {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue);
  color: #ffffff;
}

.answer-badge {
  min-width: 62px;
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--green);
  color: #ffffff;
  font-size: 0.78rem;
}

.button-stack {
  display: grid;
  gap: 8px;
}

.question-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 2px solid #dbeaf2;
  border-radius: 8px;
  background: #ffffff;
  font-size: 1.5rem;
  line-height: 1.3;
}

.question-card strong {
  display: block;
  font-size: 1.3rem;
}

.keywords-panel {
  grid-area: keywords;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 8px;
  background: #f8fbfd;
  border-right: 1px solid var(--line);
  box-shadow: 6px 0 14px rgba(15, 33, 49, 0.04);
  z-index: 5;
  min-width: 0;
}

.app.sequence-left .keywords-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 14px rgba(15, 33, 49, 0.04);
}

.keywords-heading,
.keywords-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.keywords-heading {
  color: var(--ink);
  min-height: var(--touch);
  display: flex;
  align-items: center;
  padding: 0 14px;
}

.keywords-heading h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
  font-weight: 800;
}

.keywords-card {
  padding: 10px;
}

.keywords-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.keywords-card dt {
  font-size: 0.82rem;
  font-weight: 900;
  color: var(--ink);
}

.keywords-card dd {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.22;
  font-weight: 700;
}

.keywords-card [data-keyword] {
  border-left: 3px solid transparent;
  border-radius: 6px;
  padding: 5px 6px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.keywords-card [data-keyword].active {
  border-left-color: var(--blue);
  background: #eaf8fd;
}

.app.practice-board-active {
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar topbar topbar"
    "keywords workspace sequence";
}

.app.practice-board-active.sequence-left {
  grid-template-areas:
    "topbar topbar topbar"
    "sequence workspace keywords";
}

.app.practice-board-active #coordinateGridModel > .toolbar,
.app.practice-board-active #reflectionGridModel > .toolbar {
  display: none;
}

.board-practice-panel {
  grid-area: workspace;
  position: relative;
  z-index: 5;
  margin: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 18px;
  overflow: auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 14px;
  min-height: 0;
}

.board-practice-panel[hidden] {
  display: none;
}

.board-practice-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.board-practice-header h2 {
  margin: 0;
  font-size: clamp(1.25rem, 1.7vw, 1.8rem);
}

.board-practice-header p,
.board-practice-footer,
.think-deeper-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.2vw, 1.22rem);
  line-height: 1.3;
  font-weight: 800;
}

.board-practice-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.board-practice-action {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.board-practice-action[aria-pressed="true"] {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.board-practice-badge {
  border: 2px solid #cfe4ef;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #eef7fb;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
}

.board-practice-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.board-practice-column {
  display: grid;
  align-content: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 12px;
  min-width: 0;
}

.board-practice-column h3 {
  margin: 0;
  font-size: clamp(1.05rem, 1.2vw, 1.34rem);
}

.board-practice-column ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.4em;
  font-size: clamp(0.98rem, 1.08vw, 1.22rem);
  line-height: 1.28;
  font-weight: 800;
}

.board-diagram {
  width: min(100%, 220px);
  aspect-ratio: 1;
  justify-self: center;
  border: 1px solid #d8e2ea;
  border-radius: 6px;
  background: #ffffff;
}

.board-diagram .grid {
  stroke: #dbe6ee;
  stroke-width: 0.8;
}

.board-diagram .axis {
  stroke: #31485a;
  stroke-width: 1.8;
}

.board-diagram .shape-line {
  fill: none;
  stroke: #149bd7;
  stroke-width: 2.4;
}

.board-diagram .shape-line.closed {
  fill: rgba(20, 155, 215, 0.1);
}

.board-diagram .diagram-point line {
  stroke: #102131;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.board-diagram .answer-point line {
  stroke: #16895f;
  stroke-width: 2.8;
  stroke-linecap: round;
}

.board-diagram text {
  fill: #102131;
  font: 800 12px Arial, Helvetica, sans-serif;
}

.board-practice-footer {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.think-deeper-panel {
  border: 2px solid #8fd8f3;
  border-radius: var(--radius);
  background: #eaf8fd;
  padding: 12px;
}

.think-deeper-panel[hidden] {
  display: none;
}

.think-deeper-panel h3 {
  margin: 0;
  font-size: 1.05rem;
}

.answer-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.empty-list {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.print-logo,
.print-copyright {
  display: none;
}

.instructions-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  color: var(--ink);
}

.instructions-dialog::backdrop {
  background: rgba(5, 16, 25, 0.52);
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #071018;
  color: #ffffff;
}

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

.instructions-body {
  padding: 16px 20px 22px;
  overflow: auto;
  max-height: calc(100vh - 116px);
  line-height: 1.5;
}

.instructions-body h3 {
  margin: 18px 0 6px;
}

.instructions-body h3:first-child {
  margin-top: 0;
}

.instructions-body li {
  margin: 0 0 7px;
}

@media (max-width: 980px) {
  body { overflow: auto; }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .app.practice-board-active,
  .app.practice-board-active.sequence-left {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "topbar"
      "sequence"
      "keywords"
      "workspace";
  }

  .board-practice-panel {
    margin: 8px;
  }

  .board-practice-columns {
    grid-template-columns: 1fr;
  }

  .topbar,
  .tool-surface {
    grid-template-columns: 1fr;
  }

  .workspace {
    overflow: visible;
  }

  .tool-surface {
    height: auto;
  }

  .side-panel {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .canvas-shell {
    height: 560px;
  }

  .lesson-tabs {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .preset-grid,
  .axis-row {
    grid-template-columns: 1fr;
  }
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.axis-row {
  display: grid;
  grid-template-columns: 50px 62px 50px 62px;
  gap: 6px;
  align-items: center;
}

.axis-row .number-box {
  width: 62px;
  min-width: 0;
  padding: 0 8px;
  text-align: center;
}

@media (max-width: 680px) {
  .toolbar,
  .toolbar-left,
  .toolbar-right,
  .control-group {
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right,
  .control-group,
  .wide-button,
  .primary-button,
  select {
    width: 100%;
  }

  .menu-panel {
    left: 0;
    right: auto;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body {
    overflow: visible;
    background: #ffffff;
  }

  .topbar,
  .toolbar,
  .side-panel,
  .status,
  .instructions-dialog {
    display: none !important;
  }

  .app,
  .workspace,
  .tool-surface {
    display: block;
    height: auto;
    min-height: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
    border: 0;
    background: #ffffff;
  }

  .board-wrap {
    display: block;
  }

  .canvas-shell {
    width: 100%;
    height: 178mm;
    border: 1px solid #9fb2c1;
  }

  .print-logo {
    display: block;
    width: 36mm;
    margin: 0 0 4mm;
  }

  .print-copyright {
    display: block;
    margin-top: 3mm;
    color: #5c6b78;
    font-size: 10pt;
    font-weight: 700;
  }
}
