:root {
  --ink: #17211c;
  --muted: #657069;
  --paper: #f3f0e8;
  --panel: #fffdf7;
  --line: #cfcac0;
  --green: #096c47;
  --green-soft: #d9eadf;
  --acid: #d9f24f;
  --error: #b42318;
  --error-soft: #fff0ed;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    linear-gradient(rgba(23, 33, 28, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 33, 28, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, Arial, sans-serif;
}

[hidden] { display: none !important; }
button, textarea { font: inherit; }
button { color: inherit; }
.app-shell { min-height: 100vh; }

.topbar {
  height: 72px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--ink);
  background: rgba(243, 240, 232, .88);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; letter-spacing: .06em; font-size: 14px; }
.brand b { color: var(--green); font-weight: 800; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; background: var(--acid); font: 700 12px/1 monospace; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status span { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.hero { max-width: 1440px; margin: auto; padding: clamp(48px, 8vw, 96px) clamp(20px, 5vw, 72px) clamp(32px, 5vw, 60px); display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(260px, .55fr); align-items: end; gap: 48px; }
.eyebrow, .step { margin: 0 0 14px; color: var(--green); font: 700 11px/1.2 monospace; letter-spacing: .16em; }
h1 { margin: 0; max-width: 850px; font-size: clamp(42px, 6.1vw, 88px); font-weight: 700; line-height: .98; letter-spacing: -.055em; }
h1 em { color: var(--green); font-family: Georgia, serif; font-weight: 400; }
.intro { margin: 0 0 4px; padding-left: 20px; border-left: 3px solid var(--acid); color: var(--muted); font-size: 15px; line-height: 1.75; }

.workspace { position: relative; max-width: 1440px; margin: auto; padding: 0 clamp(20px, 5vw, 72px) 70px; display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); }
.panel { min-width: 0; min-height: 610px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--ink); background: var(--panel); box-shadow: 7px 7px 0 rgba(23, 33, 28, .12); }
.panel-head { min-height: 92px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-head .step { margin-bottom: 7px; }
.panel-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.actions { display: flex; align-items: center; gap: 7px; }

.actions button, .copy-button { min-height: 36px; padding: 7px 11px; border: 1px solid var(--line); background: transparent; font-size: 12px; cursor: pointer; transition: background .16s, border-color .16s, transform .16s; }
.actions button:hover:not(:disabled), .copy-button:hover:not(:disabled) { border-color: var(--ink); background: var(--paper); transform: translateY(-1px); }
.actions .icon-button { width: 36px; padding: 0; font-size: 20px; line-height: 1; }
button:disabled { cursor: not-allowed; opacity: .42; }
.copy-button { border-color: var(--green); background: var(--green); color: white; min-width: 88px; }

.editor-wrap { position: relative; flex: 1; display: grid; grid-template-columns: 48px minmax(0, 1fr); min-height: 420px; background: #fbfaf5; overflow: hidden; }
.editor-wrap.has-error { background: #fff9f7; }
.line-numbers { padding: 20px 12px; display: flex; flex-direction: column; align-items: flex-end; overflow: hidden; border-right: 1px solid var(--line); color: #9a9d97; background: rgba(23, 33, 28, .025); font: 12px/1.65 monospace; user-select: none; }
.editor-wrap textarea { width: 100%; min-height: 420px; padding: 20px; resize: none; border: 0; outline: none; background: transparent; color: #1b3529; font: 13px/1.65 monospace; tab-size: 2; white-space: pre; overflow: auto; }

.error-card { padding: 14px 18px; display: flex; gap: 12px; border-top: 1px solid #e5a49b; background: var(--error-soft); color: var(--error); }
.error-icon { flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--error); color: white; font: 800 13px/1 Arial, sans-serif; }
.error-card strong { display: block; font-size: 13px; }
.error-card p { margin: 3px 0 0; font-size: 11px; line-height: 1.5; }

.panel-foot { min-height: 46px; padding: 0 18px; display: flex; align-items: center; gap: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; letter-spacing: .04em; }
.panel-foot span:last-child { margin-left: auto; }
.panel-foot .valid { color: var(--green); }
.panel-foot .valid::before { content: "●"; margin-right: 7px; }
.panel-foot .invalid { color: var(--error); }

.flow-arrow { z-index: 2; width: 56px; height: 56px; margin: auto -6px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; background: var(--acid); font: 26px/1 Arial, sans-serif; }
.output-panel { background: #17211c; color: #edf1e9; box-shadow: 7px 7px 0 rgba(9, 108, 71, .24); }
.output-panel .panel-head { border-color: #3a453f; }
.output-panel .step { color: var(--acid); }
.output-code { flex: 1; min-height: 466px; overflow: auto; background: radial-gradient(circle at 90% 5%, rgba(217, 242, 79, .08), transparent 28%), #17211c; }
.output-code pre { margin: 0; padding: 24px; min-width: max-content; }
.output-code code { color: #cfe8d9; font: 13px/1.75 monospace; }
.empty-state { min-height: 466px; padding: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #839087; }
.empty-state span { width: 64px; height: 64px; margin-bottom: 20px; display: grid; place-items: center; border: 1px solid #526058; border-radius: 50%; color: var(--acid); font: 700 15px/1 monospace; }
.empty-state strong { color: #dfe6df; font-size: 15px; }
.empty-state p { margin: 7px 0 0; font-size: 12px; }
.output-foot { border-color: #3a453f; color: #819087; }
.output-foot span:first-child { color: var(--acid); }

footer { padding: 28px clamp(20px, 5vw, 72px); display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
footer span { color: var(--ink); font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
footer p { margin: 0; }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 26px; }
  .intro { max-width: 620px; }
  .workspace { grid-template-columns: 1fr; }
  .panel { min-height: 560px; }
  .flow-arrow { margin: -10px auto; transform: rotate(90deg); }
}

@media (max-width: 560px) {
  .topbar { height: 62px; }
  .status { font-size: 0; }
  .hero { padding-top: 44px; }
  h1 { font-size: clamp(38px, 12vw, 56px); }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .actions { width: 100%; flex-wrap: wrap; }
  .actions button:not(.icon-button) { flex: 1; }
  .actions .icon-button { margin-left: auto; }
  .panel { min-height: 520px; }
  .editor-wrap { grid-template-columns: 40px minmax(0, 1fr); min-height: 360px; }
  .editor-wrap textarea { min-height: 360px; padding: 16px 12px; font-size: 12px; }
  .line-numbers { padding: 16px 9px; font-size: 11px; }
  .output-code, .empty-state { min-height: 380px; }
  footer { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
