:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-muted: #eef4f1;
  --border: #cfdbd5;
  --text: #18201d;
  --muted: #64716b;
  --accent: #0f766e;
  --accent-hover: #0b5f59;
  --shadow: 0 18px 45px rgba(15, 35, 30, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 260px),
    var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 2.3vw, 2.45rem);
}

h2 {
  font-size: 1.35rem;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 76px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  padding: 7px 12px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.right-col {
  position: sticky;
  top: 20px;
}

.tool-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  padding: 22px;
}

.fields-panel {
  gap: 14px;
}

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

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

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  justify-self: start;
  min-width: 150px;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary-button {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.result-inline {
  display: grid;
  gap: 16px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.message {
  min-height: 40px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

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

.preview-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 120px);
  min-height: 400px;
}

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

.preview-header .eyebrow {
  margin: 0;
}

.preview-open-btn {
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.preview-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafafa;
}

.preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(246, 248, 247, 0.85);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.preview-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

  .right-col {
    position: static;
  }

  .preview-panel {
    height: 480px;
  }
}

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 24px, 560px);
    padding: 20px 0;
  }

  .topbar {
    display: grid;
  }

  .status-pill {
    justify-self: start;
  }

  .primary-button {
    width: 100%;
  }

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