:root {
  --bg: #f7f3ec;
  --surface: #fffefa;
  --surface-soft: #fbf8f1;
  --ink: #1d242b;
  --muted: #66727d;
  --subtle: #87919a;
  --border: #ded8cd;
  --border-strong: #c9c1b5;
  --orange: #e8702a;
  --orange-dark: #b94d17;
  --green: #2d987b;
  --green-dark: #1f6f5b;
  --blue: #285f8f;
  --danger: #b8423d;
  --shadow: 0 18px 44px rgba(34, 38, 42, 0.08);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(232, 112, 42, 0.18);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.72), rgba(247, 243, 236, 0) 260px),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
}

.icon-sprite {
  display: none;
}

.app-shell {
  width: min(1520px, calc(100% - 40px));
  margin: 0 auto;
  padding: 26px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 22px rgba(34, 38, 42, 0.08);
}

.orange-dot,
.apple-dot {
  position: absolute;
  display: block;
  border-radius: 999px;
}

.orange-dot {
  width: 20px;
  height: 20px;
  left: 8px;
  bottom: 8px;
  background: var(--orange);
}

.apple-dot {
  width: 16px;
  height: 18px;
  right: 8px;
  top: 8px;
  background: var(--green);
  transform: rotate(-12deg);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 800;
}

.brand-block p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.provider-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
}

.provider-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 254, 250, 0.8);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.provider-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--subtle);
}

.provider-pill.ready::before {
  background: var(--green);
}

.provider-pill.missing::before {
  background: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(430px, 1fr) minmax(330px, 420px);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.output-panel {
  position: sticky;
  top: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 17px;
  line-height: 1.35;
  font-weight: 800;
}

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-align: right;
}

.field,
fieldset.field {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  min-width: 0;
}

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

label,
legend,
.section-title {
  color: #34414b;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 800;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input[type="text"],
input[type="number"],
select {
  min-height: 42px;
  padding: 8px 11px;
}

textarea {
  resize: vertical;
  min-height: 118px;
  padding: 11px 12px;
  line-height: 1.65;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.result-box:focus {
  border-color: var(--orange);
  box-shadow: var(--focus);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #53606a 50%),
    linear-gradient(135deg, #53606a 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 17px,
    calc(100% - 11px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.lesson-preview {
  margin: -2px 0 14px;
  padding: 10px 12px;
  border-left: 3px solid var(--blue);
  background: #f1f6fa;
  color: #34414b;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
  line-height: 1.55;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  gap: 3px;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}

.segmented input:checked + span {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(34, 38, 42, 0.08);
}

.toggle-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.toggle-row span {
  font-size: 14px;
  color: var(--ink);
}

.suggestion-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

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

.suggestion-block textarea {
  min-height: 104px;
  margin-bottom: 10px;
}

.label-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button-row,
.output-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.compact-actions {
  display: grid;
  grid-template-columns: minmax(130px, 1.25fr) 1fr 1fr 42px;
  gap: 7px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.64;
  transform: none;
}

.primary {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 10px 20px rgba(232, 112, 42, 0.22);
}

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

.secondary {
  border: 1px solid #aecbbf;
  background: #eff8f4;
  color: var(--green-dark);
}

.secondary:hover {
  background: #e3f2ec;
}

.ghost {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue);
}

.ghost:hover {
  border-color: #b4c7d8;
  background: #f2f7fb;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue);
}

.result-box {
  min-height: 440px;
  max-height: calc(100vh - 230px);
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #fffdf8);
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.75;
  outline: none;
}

.empty-state {
  color: var(--subtle);
  line-height: 1.7;
}

.output-actions {
  margin-top: 14px;
}

.output-actions .primary {
  flex: 1 1 180px;
}

.output-actions .secondary {
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: min(520px, calc(100% - 28px));
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #20272d;
  color: #fff;
  box-shadow: 0 16px 34px rgba(32, 39, 45, 0.24);
  font-size: 14px;
  line-height: 1.45;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr);
  }

  .output-panel {
    position: static;
    grid-column: 1 / -1;
  }

  .result-box {
    min-height: 260px;
    max-height: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 24px, 760px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .provider-strip {
    justify-content: flex-start;
  }

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

  .panel {
    padding: 15px;
  }

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

  .icon-button {
    width: 100%;
  }

  .label-action {
    align-items: stretch;
    flex-direction: column;
  }

  .label-action .secondary,
  .output-actions .secondary {
    width: 100%;
  }

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

@media (max-width: 480px) {
  h1 {
    font-size: 21px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .panel-heading {
    flex-direction: column;
    gap: 4px;
  }

  .panel-heading span {
    text-align: left;
  }
}
