:root {
  color-scheme: light;
  --ink: #251a14;
  --paper: #e8d6ad;
  --clay: #bd8c64;
  --line: rgba(37, 26, 20, 0.18);
  --panel: #f7f3e9;
  --panel-2: #e9eef0;
  --accent: #2c5f68;
  --accent-2: #a64532;
  --text: #201a17;
  --muted: #6c625c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(44, 95, 104, 0.08) 0 1px, transparent 1px 100%),
    linear-gradient(180deg, rgba(166, 69, 50, 0.06) 0 1px, transparent 1px 100%),
    #d9ddd2;
  background-size: 34px 34px;
}

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

.app-shell {
  min-height: 100vh;
  padding: clamp(18px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.workbench {
  width: min(1180px, 100%);
  min-height: min(820px, calc(100vh - 36px));
  display: grid;
  grid-template-columns: minmax(310px, 0.88fr) minmax(420px, 1.12fr);
  border: 1px solid rgba(32, 26, 23, 0.2);
  background: rgba(247, 243, 233, 0.94);
  box-shadow: 0 24px 80px rgba(31, 34, 28, 0.18);
}

.input-pane,
.preview-pane {
  padding: clamp(18px, 2.6vw, 34px);
}

.input-pane {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #f9f5ec, #ece6d9);
}

.brand-row,
.preview-toolbar,
.actions,
.mode-tabs {
  display: flex;
  align-items: center;
}

.brand-row {
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.95rem, 4vw, 3.7rem);
  line-height: 0.95;
  font-family: "UnifrakturMaguntia", Georgia, serif;
  font-weight: 400;
}

.status-pill {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid rgba(44, 95, 104, 0.32);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.46);
}

.mode-tabs {
  margin: 28px 0 20px;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.38);
}

.mode-tab {
  min-height: 38px;
  flex: 1 1 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.mode-tab.active {
  color: #f8f3e9;
  background: var(--accent);
}

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

textarea {
  width: 100%;
  min-height: 168px;
  margin: 8px 0 20px;
  resize: vertical;
  border: 1px solid rgba(32, 26, 23, 0.24);
  background: rgba(255, 255, 255, 0.54);
  color: var(--text);
  padding: 14px;
  outline: none;
  line-height: 1.55;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44, 95, 104, 0.14);
}

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

select,
input[type="color"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(32, 26, 23, 0.22);
  background: rgba(255, 255, 255, 0.58);
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

input[type="range"] {
  width: 100%;
  min-height: 42px;
  accent-color: var(--accent-2);
}

.actions {
  margin-top: 24px;
  gap: 10px;
  flex-wrap: wrap;
}

.actions button {
  min-width: 88px;
  min-height: 42px;
  border: 1px solid rgba(32, 26, 23, 0.22);
  color: #fffaf0;
  background: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.actions button:not(:first-child) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.52);
}

.actions button.active {
  color: #fffaf0;
  background: var(--accent-2);
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(160px, 0.62fr);
  gap: 16px;
  background: #edf0ec;
}

.preview-toolbar {
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.artboard {
  position: relative;
  overflow: hidden;
  width: min(100%, 548px);
  aspect-ratio: 274 / 176;
  min-height: 0;
  justify-self: center;
  border: 1px solid rgba(32, 26, 23, 0.2);
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3.4vw, 34px);
  gap: clamp(10px, 2vw, 18px);
}

.artboard::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: none;
  mix-blend-mode: multiply;
}

.surface-white {
  background: #fff;
}

.surface-black {
  background: #000;
}

.surface-transparent {
  background:
    linear-gradient(45deg, rgba(32, 26, 23, 0.09) 25%, transparent 25% 75%, rgba(32, 26, 23, 0.09) 75%),
    linear-gradient(45deg, rgba(32, 26, 23, 0.09) 25%, transparent 25% 75%, rgba(32, 26, 23, 0.09) 75%);
  background-color: transparent;
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

.rendered {
  position: relative;
  z-index: 1;
  max-width: 100%;
  color: var(--ink);
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

.render-token {
  display: inline-block;
  margin: 0 0.12em 0.18em;
  padding-bottom: 0.08em;
}

.render-token.phonetic-mark {
  border-bottom: 2px solid #c92121;
}

.translation-strip {
  min-height: 54px;
  border: 1px solid rgba(32, 26, 23, 0.14);
  background: rgba(255, 255, 255, 0.62);
  padding: 10px 12px;
}

.translation-strip span {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 850;
}

.translation-strip p {
  margin: 0;
  color: #2e2925;
  font-size: 0.9rem;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.rendered.gothic {
  font-family: "UnifrakturMaguntia", Georgia, serif;
}

.font-maguntia {
  font-family: "UnifrakturMaguntia", Georgia, serif;
}

.font-cook {
  font-family: "UnifrakturCook", Georgia, serif;
}

.font-pirata {
  font-family: "Pirata One", Georgia, serif;
}

.font-grenze {
  font-family: "Grenze Gotisch", Georgia, serif;
}

.font-cinzel {
  font-family: "Cinzel Decorative", Georgia, serif;
}

.font-cuneiform {
  font-family: "Noto Sans Cuneiform", "Segoe UI Historic", serif;
}

.rendered.cuneiform {
  font-family: "Noto Sans Cuneiform", "Segoe UI Historic", serif;
  line-height: 1.35;
}

.rendered.seal {
  text-transform: uppercase;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  padding: 0.26em 0.1em;
}

.rendered.tablet {
  filter: drop-shadow(1px 2px 0 rgba(65, 42, 24, 0.24));
}

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

.pipeline div {
  min-height: 104px;
  border: 1px solid rgba(32, 26, 23, 0.14);
  background: rgba(255, 255, 255, 0.55);
  padding: 12px;
}

.pipeline span {
  display: block;
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
}

.pipeline p {
  margin: 0;
  color: #3d342e;
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.derivation-panel {
  min-height: 0;
  border: 1px solid rgba(32, 26, 23, 0.16);
  background: rgba(255, 255, 255, 0.6);
  display: grid;
  grid-template-rows: auto 1fr;
}

.derivation-title {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(32, 26, 23, 0.12);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
}

#derivationText {
  margin: 0;
  min-height: 148px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  color: #2e2925;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .app-shell {
    align-items: stretch;
    padding: 12px;
  }

  .workbench {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .input-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-pane {
    grid-template-rows: auto auto auto auto;
  }

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