:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #687079;
  --line: #d8dde3;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #126c69;
  --accent-dark: #0e5351;
  --gold: #b7791f;
  --rose: #a23b53;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(18, 108, 105, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(162, 59, 83, 0.1), transparent 35%),
    var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
}

.workbench,
.result-area {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.workbench {
  border-radius: 8px;
  overflow: hidden;
}

.result-area {
  border-radius: 8px;
  padding: 18px;
}

.topbar {
  min-height: 112px;
  padding: 20px;
  color: #fff;
  background: linear-gradient(120deg, #164e63, #126c69 58%, #7b2d42);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

.topbar p {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  line-height: 1.6;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}

.input-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.wide {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.lines-panel legend {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.line-row select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

.field input:focus,
.field select:focus,
.line-row select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(18, 108, 105, 0.14);
}

.lines-panel {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
}

.line-row {
  display: grid;
  grid-template-columns: 52px minmax(128px, 1fr) minmax(118px, auto);
  align-items: center;
  gap: 10px;
}

.line-row span {
  color: #41464d;
  font-weight: 600;
}

.coins {
  min-height: 30px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: right;
}

.coin-face {
  display: inline-grid;
  width: 24px;
  height: 24px;
  margin-left: 3px;
  place-items: center;
  border: 1px solid #d4b06a;
  border-radius: 50%;
  color: #6f4712;
  background: #fff7df;
  font-size: 12px;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 10px;
}

.primary,
.secondary {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary {
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  color: var(--ink);
  background: #f3f6f6;
  border-color: var(--line);
}

.summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-item {
  min-height: 72px;
  padding: 12px;
  border-left: 4px solid var(--accent);
  background: #f7fbfa;
}

.summary-item:nth-child(2n) {
  border-left-color: var(--gold);
  background: #fffaf0;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
}

.summary-small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  margin-top: 3px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f5f7f8;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.yao {
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 18px;
  font-weight: 700;
}

.moving {
  color: var(--rose);
}

.marker {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  font-size: 13px;
}

.empty {
  color: var(--muted);
}

.ai-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.ai-panel header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f7fbfa;
}

.ai-panel h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

#aiStatus {
  color: var(--muted);
  font-size: 13px;
}

.ai-answer {
  min-height: 96px;
  padding: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.history-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-panel header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fffaf0;
}

.history-panel h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.text-button {
  border: 0;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
}

.history-list {
  display: grid;
}

.history-empty {
  padding: 16px 14px;
  color: var(--muted);
}

.history-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

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

.history-title {
  font-weight: 700;
  line-height: 1.45;
}

.history-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.history-actions {
  display: flex;
  align-items: start;
  gap: 6px;
}

.mini-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #f7f9f9;
  cursor: pointer;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 720px);
    padding: 10px 0;
  }

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

@media (max-width: 520px) {
  .input-grid,
  .actions {
    grid-template-columns: 1fr;
  }

  .field {
    grid-column: 1 / -1;
  }

  .topbar {
    min-height: 100px;
    padding: 16px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .line-row {
    grid-template-columns: 48px 1fr;
  }

  .coins {
    grid-column: 2;
    text-align: left;
  }
}
