:root {
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    'Meiryo',
    sans-serif;
  color-scheme: light;
  --bg: #f2f5f4;
  --surface: #fff;
  --text: #172f38;
  --muted: #485d66;
  --line: #71858d;
  --accent: #086b66;
  --accent-text: #fff;
  --soft: #e8f3f1;
  --error: #a01d24;
  --focus: #0066d6;
  --panel: #fbfcfc;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #101d24;
  --surface: #192b35;
  --text: #f1f5f7;
  --muted: #c2d0d6;
  --line: #8a9ea8;
  --accent: #8ce4d8;
  --accent-text: #092d29;
  --soft: #223c43;
  --error: #ffb3b6;
  --focus: #ffd36b;
  --panel: #213640;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
}
button,
input,
textarea,
select {
  font: inherit;
}
a {
  color: var(--accent);
}
a,
button,
input,
textarea,
select,
summary {
  touch-action: manipulation;
}
button,
summary,
select {
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: 0.55;
}
button,
input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
}
:where(button, select) {
  min-height: 44px;
  padding: 0.5rem 0.8rem;
}
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 700;
}
input:not([type='checkbox']),
textarea,
select {
  width: 100%;
  min-width: 0;
  padding: 0.65rem;
}
textarea {
  resize: vertical;
  min-height: 5rem;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
p {
  margin: 0.55rem 0;
}
h1,
h2,
h3 {
  line-height: 1.35;
  margin: 0 0 0.75rem;
}
h1 {
  font-size: clamp(1.45rem, 4vw, 2rem);
}
h2 {
  font-size: 1.3rem;
}
h3 {
  font-size: 1.1rem;
}
small,
.small {
  font-size: 0.875rem;
}
.muted {
  color: var(--muted);
}
.wrap {
  max-width: 1200px;
  margin: auto;
  padding: 1rem;
}
.site-header {
  position: relative;
  text-align: center;
  padding: 1.75rem 0 1rem;
}
.header-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.intro {
  max-width: 56rem;
  margin: 0 auto 1rem;
}
.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 1rem 0;
}
.tabs button {
  padding: 0.6rem 0.15rem;
  font-weight: 700;
}
.tabs [aria-selected='true'] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.tabs button:focus-visible {
  outline-offset: 1px;
}
.layout {
  display: grid;
  gap: 1rem;
  align-items: start;
}
.layout > * {
  min-width: 0;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 1rem;
  min-width: 0;
}
.card > *:last-child {
  margin-bottom: 0;
}
.field {
  display: block;
  margin: 0.8rem 0;
}
.field > span {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.field .small {
  font-weight: 400;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.row > * {
  min-width: 0;
}
.row .field {
  flex: 1 1 10rem;
}
.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.7rem 0;
}
.button-row > a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.4rem 0.2rem;
}
.switch {
  display: inline-flex;
  gap: 0.6rem;
  align-items: center;
  min-height: 44px;
  padding: 0.4rem 0.2rem;
  cursor: pointer;
}
.switch input {
  appearance: none;
  position: relative;
  flex: 0 0 2.4rem;
  width: 2.4rem;
  height: 1.35rem;
  border: 2px solid var(--line);
  border-radius: 2rem;
  background: var(--panel);
  margin: 0;
}
.switch input:after {
  content: '';
  position: absolute;
  left: 0.1rem;
  top: 0.1rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: var(--text);
}
.switch input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked:after {
  left: 1.1rem;
  background: var(--accent-text);
}
.disk {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  max-width: 560px;
  margin: auto;
  border-radius: 0.6rem;
  background: var(--surface);
}
.legend {
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
  margin: 0.5rem 0;
}
.progress {
  color: var(--accent);
  font-weight: 700;
}
.current {
  font-weight: 650;
  min-height: 3.2em;
}
.phase {
  font-size: 0.875rem;
  color: var(--muted);
  min-height: 1.6em;
}
.speed {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.speed select {
  width: auto;
  flex: 1;
  max-width: 12rem;
}
.result {
  overflow-wrap: anywhere;
  word-break: normal;
  border-left: 4px solid var(--accent);
  padding: 0.5rem 0.8rem;
  background: var(--soft);
  margin: 0.7rem 0;
}
.result output {
  font-size: 1.3rem;
  font-weight: 700;
  display: block;
  white-space: pre-wrap;
}
.result .tokens {
  font-size: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.token {
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  padding: 0.2rem 0.4rem;
}
.error {
  border-left: 4px solid var(--error);
  padding: 0.7rem;
  color: var(--error);
  background: var(--surface);
  overflow-wrap: anywhere;
}
.notice {
  padding: 0.7rem;
  background: var(--soft);
  border-radius: 0.4rem;
  overflow-wrap: anywhere;
}
.status {
  margin-top: 0.7rem;
  color: var(--accent);
  overflow-wrap: anywhere;
}
.status:empty {
  display: none;
}
details {
  border-top: 1px solid var(--line);
  padding-top: 0.4rem;
  margin-top: 0.7rem;
}
summary {
  min-height: 44px;
  padding: 0.55rem 0;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.mapping {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(5.8rem, 100%), 1fr));
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.mapping button {
  overflow-wrap: anywhere;
  padding: 0.4rem;
}
.mapping .selected {
  border: 3px solid var(--accent);
  background: var(--soft);
}
.route-list {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
}
.route-list li {
  border: 1px solid var(--line);
  padding: 0.3rem 0.5rem;
  border-radius: 0.3rem;
}
.route-list .done {
  background: var(--soft);
}
.route-list .active {
  outline: 2px solid var(--accent);
}
.theory-grid {
  display: grid;
  gap: 1rem;
}
.theory-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.theory-nav a {
  display: flex;
  min-height: 44px;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--surface);
  text-decoration: none;
}
.sources {
  padding-left: 1.3rem;
  overflow-wrap: anywhere;
}
.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 1.5rem;
  padding: 1rem 0;
  text-align: center;
  color: var(--muted);
}
.site-footer a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
}
.site-footer p {
  max-width: 60rem;
  margin: 0.5rem auto;
}
dialog {
  max-width: min(42rem, calc(100% - 2rem));
  max-height: 85dvh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--surface);
  color: var(--text);
  padding: 1.2rem;
}
dialog::backdrop {
  background: #0008;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.copy-fallback {
  min-height: 3rem;
}
.history {
  font-size: 0.875rem;
}
.history li {
  overflow-wrap: anywhere;
}
.figure-caption {
  font-size: 0.875rem;
  color: var(--muted);
}
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }
  .card {
    padding: 1.3rem;
  }
  .theory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .site-header {
    padding-inline: 190px;
  }
  .header-actions {
    position: absolute;
    right: 0;
    top: 1.1rem;
    max-width: 185px;
    margin: 0;
    gap: 0.3rem;
  }
  .header-actions button {
    padding: 0.4rem 0.6rem;
  }
}
@media (hover: hover) {
  button:not(:disabled):hover {
    filter: brightness(0.94);
  }
  summary:hover,
  a:hover {
    text-decoration: underline;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
button {
  min-width: 44px;
}

@media (max-width: 499px) {
  html[lang='en'] .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.header-actions .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
}
.icon-button svg {
  display: block;
}

.learning-diagram {
  margin: 1rem 0;
  padding: 0.8rem;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
}
.diagram-caption {
  font-weight: 700;
}
.diagram-kind {
  display: block;
  font-weight: 400;
  color: var(--muted);
}
.diagram-stages {
  padding-left: 1.25rem;
  margin: 0.75rem 0;
}
.diagram-stage {
  padding: 0.5rem 0;
}
.diagram-label,
.diagram-description {
  display: block;
}
.diagram-description,
.diagram-note,
.diagram-passage {
  font-size: 0.875rem;
}
.diagram-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.35rem 0;
}
.diagram-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-width: 2rem;
  padding: 0.2rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
}
.diagram-auxiliary {
  border-style: dashed;
}
.diagram-position {
  color: var(--muted);
  font-size: 0.875rem;
}
.diagram-token[data-group='odd'] {
  border-bottom: 4px solid var(--accent);
}
.diagram-token[data-group='even'] {
  border-bottom: 4px double var(--text);
}
.diagram-passage {
  display: flex;
  gap: 0.4rem 1rem;
  flex-wrap: wrap;
}
.diagram-strand {
  margin: 0.4rem 0;
}
.diagram-strand-label {
  font-size: 0.875rem;
}
.diagram-mapping {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.875rem;
  table-layout: fixed;
}
.diagram-mapping th,
.diagram-mapping td {
  padding: 0.25rem;
  border: 1px solid var(--line);
  text-align: center;
  overflow-wrap: anywhere;
}
.diagram-mapping th:first-child {
  width: 35%;
}

/* Separate explanatory backgrounds from the controls that follow them. */
.notice {
  margin-block: 0.8rem;
}
.speed {
  margin-block: 1rem 0.5rem;
}
.speed + .switch {
  margin-bottom: 0.5rem;
}
.button-row {
  margin-block: 1rem;
}
.card > .row:first-of-type {
  margin-bottom: 0.75rem;
}
.card > .field + .field {
  margin-top: 1.25rem;
}
.help-dialog {
  width: min(42rem, calc(100% - 2rem));
  padding: 0;
  overflow: hidden;
}
.help-dialog[open] {
  display: flex;
  flex-direction: column;
}
.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.help-header h2 {
  margin: 0;
  font-size: 1.2rem;
}
.help-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.75rem;
  line-height: 1;
}
.help-body {
  overflow-y: auto;
  padding: 1rem;
  min-height: 0;
}
.help-section + .help-section {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  margin-top: 1rem;
}
.help-section h3 {
  margin-bottom: 0.5rem;
}
.help-section ul,
.help-section ol {
  padding-left: 1.35rem;
  margin: 0.5rem 0 0;
}
.help-section li + li {
  margin-top: 0.55rem;
}

@media (min-width: 900px) {
  .disk {
    max-width: min(480px, 48dvh);
  }
}
