:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f0f4fa;
  --text: #152238;
  --muted: #55627a;
  --accent: #2a6df4;
  --accent-strong: #1f57c2;
  --border: #d9e2f0;
  --card-shadow: 0 10px 24px rgba(18, 32, 58, 0.08);
  --focus-ring: 0 0 0 3px rgba(42, 109, 244, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.45;
  background: linear-gradient(180deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 92%, var(--accent) 8%) 100%);
  color: var(--text);
  min-height: 100vh;
}

.container {
  width: min(1160px, 94vw);
  margin: 1.2rem auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 1.85rem);
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.inline-field {
  min-width: 140px;
}

.switch-label {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
}

.lang-chip {
  min-width: 40px;
  text-align: center;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  transition: background-color 140ms ease, color 140ms ease;
}

.lang-chip.active {
  background: var(--accent);
  color: #fff;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.panel {
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
}

.panel.card,
.outputs > .card,
.theory.card {
  padding: 1rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.field label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: var(--surface-alt);
  color: var(--text);
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.toggle-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.input-note,
.note,
.status,
.progress,
.app-footer,
.theory-content {
  color: var(--muted);
}

.button-row {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

.utility-row {
  margin-top: 1.1rem;
}

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.outputs > h2 {
  margin-top: 0;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 0.7rem;
}

.metric-card {
  padding: 0.8rem;
}

.metric-card h3 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.metric-card p {
  margin: 0.45rem 0 0;
  font-size: 1.12rem;
  font-weight: 600;
  word-break: break-word;
}

.chart-card,
.viz-card,
.theory {
  margin-top: 0.85rem;
}

.chart-card h3,
.viz-card h3 {
  margin-top: 0;
}

.chart-wrap {
  min-height: 220px;
  height: 32vh;
  max-height: 300px;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
}

#throwCanvas {
  width: 100%;
  min-height: 200px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.theory summary {
  cursor: pointer;
  font-weight: 600;
}

.theory-content p {
  margin: 0.6rem 0;
}

.deviation-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.4rem;
}

.deviation-table th,
.deviation-table td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 0.45rem 0.3rem;
  font-size: 0.92rem;
}

.deviation-table th {
  color: var(--muted);
  width: 56%;
}

#stepExplain {
  margin-top: 0.75rem;
  min-height: 1.1rem;
}

.status {
  min-height: 1.2rem;
}

.app-footer {
  text-align: center;
  margin-bottom: 1.2rem;
}

.fade-in {
  animation: fadeInUp 220ms ease both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 260px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
