:root {
  color-scheme: light;
  --background: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f7f7f7;
  --text: #202020;
  --muted: #707070;
  --line: #e5e5e5;
  --accent: #222222;
  --success: #18794e;
  --success-surface: #f1faf5;
  --error: #c9342f;
  --error-surface: #fff5f4;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(900px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 34px;
}

.site-header {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.language-toggle,
.restart-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.language-toggle:hover,
.restart-button:hover,
.operation-button:hover:not(:disabled) {
  border-color: #c9c9c9;
  background: var(--surface-hover);
}

.main-content {
  padding: 36px 0 64px;
}

.card {
  margin-bottom: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.intro-card {
  padding: 36px;
}

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

h1,
h2,
p {
  overflow-wrap: break-word;
}

h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1.15;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.025em;
}

.intro {
  max-width: 640px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.75;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.section-heading.compact {
  margin-bottom: 18px;
}

.goal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 30px;
}

.goal {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.goal.current {
  border-color: var(--accent);
  color: var(--text);
}

.goal.complete {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.goal-arrow {
  color: #b0b0b0;
}

.progress-text {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.display-panel {
  display: flex;
  min-height: 190px;
  margin: 24px 0 16px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--background);
}

.display-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.display-value {
  margin-top: 8px;
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  letter-spacing: -0.06em;
  line-height: 1;
}

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

.operation-button {
  display: flex;
  min-height: 88px;
  padding: 14px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.operation-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.operation-symbol {
  font-size: 1.45rem;
  font-weight: 650;
}

.operation-name {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.result {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid;
  border-radius: 10px;
}

.result.success {
  border-color: #b9dec9;
  background: var(--success-surface);
  color: var(--success);
}

.result.failure {
  border-color: #efcbc8;
  background: var(--error-surface);
  color: var(--error);
}

.result strong {
  font-size: 0.9rem;
}

.result p {
  margin: 6px 0 0;
  font-size: 0.82rem;
  line-height: 1.6;
}

.step-count {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  font-size: 0.84rem;
}

.history-item:last-child {
  padding-bottom: 0;
}

.history-index,
.history-expression {
  font-variant-numeric: tabular-nums;
}

.history-index {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-result {
  font-weight: 700;
}

.history-item.failed .history-result {
  color: var(--error);
}

.history-reason {
  grid-column: 2 / -1;
  margin: -6px 0 0;
  color: var(--error);
  font-size: 0.75rem;
}

.empty-history {
  margin: 0;
  padding: 34px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.rules {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.rules ul {
  margin: 16px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.8;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 34px;
  color: #686d76;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.footer-site-name,
.site-footer a {
  color: #161719;
}

.site-footer a {
  text-decoration: none;
}

.site-footer a:hover {
  color: #0071e3;
}

.brand:focus-visible,
.language-toggle:focus-visible,
.restart-button:focus-visible,
.operation-button:focus-visible,
.site-footer a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100% - 28px, 900px);
  }

  .site-header {
    min-height: 76px;
  }

  .main-content {
    padding: 28px 0 48px;
  }

  .card,
  .intro-card {
    padding: 20px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .display-panel {
    min-height: 160px;
  }

  .operation-button {
    min-height: 82px;
    padding: 10px 6px;
  }

  .history-item {
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
