:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #14171a;
  --muted: #667085;
  --line: #d8dde3;
  --accent: #b42318;
  --accent-soft: #fff1f0;
  --shadow: 0 16px 40px rgba(20, 23, 26, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto;
  display: grid;
  gap: 16px;
}

.topbar,
.panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

p,
.section-title span {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

button,
input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

button {
  min-height: 38px;
  padding: 0 12px;
}

select {
  min-height: 40px;
  padding: 0 10px;
}

.language-links {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
}

.language-links a {
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
}

.language-links a.active {
  color: var(--accent);
}

button {
  cursor: pointer;
}

.panel {
  padding: 20px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.grid,
.bucket-table,
.affix-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font-size: 15px;
}

.affix-builder {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.section-title.compact {
  margin-bottom: 12px;
}

.affix-controls {
  grid-template-columns: minmax(0, 2fr) minmax(120px, 1fr) auto;
  align-items: end;
}

.affix-controls button {
  min-height: 40px;
}

.affix-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.affix-list p {
  font-size: 13px;
}

.affix-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.affix-row span:nth-child(2) {
  color: var(--muted);
}

.affix-row button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.result-panel {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
  align-items: center;
}

#formulaText {
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.breakdown-list {
  margin: 16px 0 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
}

.breakdown-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.breakdown-list dt,
.breakdown-list dd {
  margin: 0;
  font-size: 13px;
}

.breakdown-list dt {
  color: var(--muted);
}

.breakdown-list dd {
  color: var(--text);
  font-weight: 650;
  text-align: right;
}

#totalDamage {
  min-width: 240px;
  padding: 18px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 30px;
  font-weight: 800;
  text-align: right;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    margin: 16px auto;
  }

  .topbar,
  .result-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .grid,
  .bucket-table,
  .affix-controls,
  .breakdown-list {
    grid-template-columns: 1fr;
  }

  .affix-row {
    grid-template-columns: 1fr;
  }

  #totalDamage {
    min-width: 0;
    text-align: left;
  }
}
