:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --soft: #f9faf7;
  --text: #23251f;
  --muted: #667063;
  --line: #d8ded2;
  --gold: #a47425;
  --green: #426b57;
  --ink: #1d2d2a;
  --danger: #9a3b2f;
  --shadow: 0 18px 38px rgba(43, 49, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(66, 107, 87, 0.09), rgba(245, 243, 238, 0) 34%), var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  width: min(1420px, calc(100% - 28px));
  margin: 0 auto;
  padding:
    calc(26px + env(safe-area-inset-top, 0px))
    env(safe-area-inset-right, 0px)
    calc(26px + env(safe-area-inset-bottom, 0px))
    env(safe-area-inset-left, 0px);
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 18px;
  align-items: end;
  margin-bottom: 20px;
}

.masthead h1,
.panel-head h2 {
  margin: 0;
  color: var(--ink);
}

.masthead h1 {
  font-size: 32px;
  line-height: 1.2;
}

.masthead p {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.status-panel,
.input-panel,
.output-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.status-panel,
.input-panel,
.output-panel {
  padding: 18px;
}

.status-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.status-panel strong {
  display: block;
  margin-top: 8px;
  color: var(--green);
}

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

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

label span,
.option-panel legend,
.conversion-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--text);
  outline: none;
}

input,
select {
  height: 42px;
  margin-top: 7px;
  padding: 0 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(66, 107, 87, 0.12);
}

.option-panel {
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.check-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.check-row span {
  color: var(--text);
  font-weight: 500;
  line-height: 1.5;
}

.action-row,
.button-cluster {
  display: flex;
  gap: 10px;
  align-items: center;
}

.action-row {
  margin-top: 18px;
}

button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 15px;
  cursor: pointer;
  font-weight: 800;
}

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

.secondary-button,
.ghost-button {
  background: #fff;
  color: var(--green);
  border-color: var(--line);
}

.conversion-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: #eef4ec;
  border: 1px solid #d4e2d2;
}

.conversion-box strong {
  display: block;
  margin-top: 7px;
  color: var(--green);
}

.history-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.history-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
}

.compact-button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  padding: 12px;
}

.history-title {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.45;
}

.history-meta,
.empty-history {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.history-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.danger-button {
  color: var(--danger);
}

textarea {
  min-height: 690px;
  resize: vertical;
  padding: 18px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.invalid {
  border-color: var(--danger);
}

@media (max-width: 980px) {
  .masthead,
  .workspace {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 560px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 760px);
  }

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

  .panel-head,
  .action-row,
  .button-cluster,
  .history-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  button {
    width: 100%;
  }
}
