:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #1e2528;
  --muted: #627071;
  --line: #d9d4c8;
  --accent: #0f7b7e;
  --accent-strong: #095f61;
  --accent-soft: #dff3ef;
  --shadow: 0 18px 50px rgba(28, 35, 38, 0.12);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111719;
  --surface: #182123;
  --surface-strong: #202b2e;
  --text: #f2f4ef;
  --muted: #aab8b6;
  --line: #314144;
  --accent: #6cc7bd;
  --accent-strong: #91ddd5;
  --accent-soft: #173b3a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent-strong);
}

button,
select,
textarea {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 36px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.home-link {
  font-weight: 700;
  text-decoration: none;
}

.theme-toggle {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(0, 160px) minmax(0, 1080px) minmax(0, 160px);
  gap: clamp(16px, 2.5vw, 28px);
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 36px);
}

.ad-rail {
  display: flex;
  justify-content: center;
}

.ad-slot {
  position: sticky;
  top: 86px;
  display: grid;
  width: 160px;
  height: 600px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  overflow: hidden;
}

.tool-panel {
  min-width: 0;
}

.title-block {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 4.5vw, 52px);
  line-height: 1.14;
  letter-spacing: 0;
}

.title-block p:last-child {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.control-grid,
.editor-block,
.preview-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px;
}

label span,
.field-header h2 {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  padding: 8px 36px 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
}

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

.editor-block,
.preview-block {
  padding: 16px;
}

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

.field-header h2 {
  margin: 0;
}

.button-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

textarea {
  display: block;
  width: 100%;
  min-height: 310px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  line-height: 1.75;
}

textarea:focus,
select:focus,
button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

.primary-button,
.ghost-button {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--accent-strong);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.stats,
#statusText {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.preview-block {
  margin-top: 18px;
}

.preview {
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

ruby {
  ruby-position: over;
  margin-inline-end: 0.18em;
}

rt {
  color: var(--accent-strong);
  font-size: 0.62em;
  font-weight: 700;
}

.site-footer {
  padding: 24px clamp(16px, 4vw, 36px) 34px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .page-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .ad-rail {
    display: none;
  }
}

@media (max-width: 760px) {
  .site-header {
    padding: 10px 14px;
  }

  .page-shell {
    padding: 18px 14px 24px;
  }

  .control-grid,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 32px;
  }

  textarea {
    min-height: 230px;
  }

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

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .button-row {
    width: 100%;
  }
}
