/* ==========================================================================
   Table Converter — "drafting table" identity.
   Cool graph-paper canvas, ink-navy strokes, one warm amber accent, and
   box-drawing corner glyphs as the signature. System monospace, no CDN deps.
   ========================================================================== */

:root {
  --paper:        #e9edf3;
  --paper-line:   #d7dfe9;
  --panel:        #f7f9fc;
  --ink:          #16202e;
  --ink-soft:     #4c5b6e;
  --ink-faint:    #8494a6;
  --stroke:       #2b3a4e;
  --stroke-soft:  #c3ccd8;
  --accent:       #d9791b;    /* amber */
  --accent-deep:  #b45f0e;
  --accent-ink:   #3a2503;
  --danger:       #b5382e;
  --focus:        #1f6feb;
  --radius:       10px;
  --shadow:       0 1px 0 rgba(22,32,46,.04), 0 10px 30px -18px rgba(22,32,46,.45);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", "Roboto Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       #0e1620;
    --paper-line:  #17222f;
    --panel:       #131d29;
    --ink:         #e7edf3;
    --ink-soft:    #9fb0c2;
    --ink-faint:   #63758a;
    --stroke:      #6b839c;
    --stroke-soft: #2a3a4c;
    --accent:      #e8912f;
    --accent-deep: #f6a94a;
    --accent-ink:  #1c1204;
    --danger:      #e06a5f;
    --focus:       #5b9bff;
    --shadow:      0 1px 0 rgba(0,0,0,.2), 0 14px 34px -18px rgba(0,0,0,.7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  background-color: var(--paper);
  /* graph-paper grid */
  background-image:
    linear-gradient(var(--paper-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 26px 26px;
  background-position: -1px -1px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: .5rem .9rem;
  border-radius: 0 0 var(--radius) 0;
  z-index: 20;
}
.skip-link:focus { left: 0; }

/* --- masthead ------------------------------------------------------------ */

.masthead {
  padding: clamp(1.75rem, 5vw, 3.25rem) 1.25rem 1.25rem;
  text-align: center;
}
.masthead__inner { max-width: 62rem; margin: 0 auto; }

.wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(.4rem, 2vw, 1rem);
  flex-wrap: wrap;
}
.wordmark__glyphs {
  font-family: var(--mono);
  font-size: clamp(1.1rem, 4vw, 2rem);
  color: var(--accent);
  letter-spacing: -.05em;
  line-height: 1;
}
.wordmark__title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.35rem, 5vw, 2.35rem);
  letter-spacing: -.02em;
  margin: 0;
  color: var(--ink);
}
.masthead__tag {
  margin: .85rem auto 0;
  max-width: 40rem;
  color: var(--ink-soft);
  font-size: clamp(.92rem, 2.4vw, 1.02rem);
}

/* --- layout -------------------------------------------------------------- */

.work {
  max-width: 74rem;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 60rem) {
  .grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "input  output"
      "ctrl   ctrl";
    align-items: start;
  }
  .panel--input  { grid-area: input; }
  .panel--output { grid-area: output; }
  .controls      { grid-area: ctrl; }
}

/* --- panels (signature: box-drawing corners) ---------------------------- */

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem;
  display: flex;
  flex-direction: column;
}
.panel::before,
.panel::after {
  position: absolute;
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
  opacity: .85;
  pointer-events: none;
}
.panel::before { content: "\250C"; top: 5px; left: 7px; }   /* ┌ */
.panel::after  { content: "\2518"; bottom: 5px; right: 8px; } /* ┘ */

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: 0 .35rem .55rem;
}
.panel__title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: .82rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink);
}
.panel__hint {
  font-size: .74rem;
  color: var(--ink-faint);
  font-style: italic;
}

.editor {
  width: 100%;
  min-height: 15rem;
  resize: vertical;
  border: 1px solid var(--stroke-soft);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: .9rem;
  line-height: 1.55;
  padding: .8rem .85rem;
  tab-size: 4;
}
.editor::placeholder { color: var(--ink-faint); }
.editor:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}
.editor--output { background: var(--panel); }
@media (min-width: 60rem) {
  .editor { min-height: 18rem; }
}

.status {
  margin: .5rem .35rem 0;
  min-height: 1.1em;
  font-size: .8rem;
  color: var(--ink-soft);
}
.status[data-kind="empty"] { color: var(--accent-deep); font-style: italic; }
.status[data-kind="ok"]    { color: var(--ink-faint); }

/* --- controls ------------------------------------------------------------ */

.controls {
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1.1rem 1.4rem;
}
.control {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.control legend {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0;
}
.control legend label { color: inherit; cursor: pointer; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--stroke-soft);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
}
.seg { position: relative; margin: 0; }
.seg input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.seg span {
  display: block;
  padding: .48rem .85rem;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--ink-soft);
  white-space: nowrap;
  border-left: 1px solid var(--stroke-soft);
  transition: background-color .12s ease, color .12s ease;
}
.seg:first-child span { border-left: 0; }
.seg input:hover + span { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.seg input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.seg input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.control--width { min-width: 8rem; }
.width-field {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--stroke-soft);
  border-radius: 8px;
  background: var(--paper);
  padding: .1rem .55rem .1rem .1rem;
  width: max-content;
}
.width-field input {
  width: 4.2rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: .9rem;
  padding: .42rem .5rem;
  text-align: right;
}
.width-field input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-radius: 6px; }
.width-field__unit { font-family: var(--mono); font-size: .74rem; color: var(--ink-faint); }
.control--width.is-disabled { opacity: .45; }
.control--width.is-disabled .width-field { background: transparent; }
.width-field input:disabled { cursor: not-allowed; }

.control__note {
  margin: 0;
  font-size: .68rem;
  color: var(--ink-faint);
  max-width: 12rem;
}

/* header checkbox */
.check {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.check input {
  appearance: none;
  -webkit-appearance: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  border: 1px solid var(--stroke-soft);
  border-radius: 5px;
  background: var(--paper);
  display: grid;
  place-content: center;
  cursor: pointer;
}
.check input::before {
  content: "";
  width: .6rem;
  height: .6rem;
  transform: scale(0);
  transition: transform .1s ease;
  background: var(--accent-ink);
  clip-path: polygon(14% 44%, 0 65%, 42% 100%, 100% 16%, 82% 0%, 40% 66%);
}
.check input:checked {
  background: var(--accent);
  border-color: var(--accent-deep);
}
.check input:checked::before { transform: scale(1); }
.check input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.control--header.is-disabled { opacity: .45; }
.control--header.is-disabled .check,
.check input:disabled { cursor: not-allowed; }

.actions {
  display: flex;
  gap: .6rem;
  margin-left: auto;
  align-self: flex-end;
}

/* --- buttons ------------------------------------------------------------- */

.btn {
  font-family: var(--mono);
  font-size: .86rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: .55rem 1.05rem;
  cursor: pointer;
  transition: transform .08s ease, background-color .12s ease, border-color .12s ease, color .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent-deep);
  box-shadow: 0 1px 0 var(--accent-deep);
}
.btn--primary:hover { background: var(--accent-deep); color: #fff; }

.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--stroke-soft);
}
.btn--ghost:hover { border-color: var(--stroke); color: var(--ink); }

.btn--copy {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--stroke-soft);
  padding: .32rem .8rem;
  font-size: .78rem;
}
.btn--copy:hover:not(:disabled) { border-color: var(--stroke); color: var(--ink); }
.btn--copy:disabled { opacity: .4; cursor: not-allowed; }
.btn--copy.is-done {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent-deep);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: color-mix(in srgb, var(--danger) 70%, black);
}
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }

/* --- modal --------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 1.25rem; }
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  backdrop-filter: blur(2px);
}
.modal__card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.55);
  padding: 1.5rem 1.6rem 1.3rem;
  max-width: 26rem;
  width: 100%;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__corner { position: absolute; font-family: var(--mono); color: var(--accent); line-height: 1; }
.modal__corner--tl { top: 6px; left: 8px; }
.modal__corner--tr { top: 6px; right: 9px; }
.modal__corner--bl { bottom: 6px; left: 8px; }
.modal__corner--br { bottom: 6px; right: 9px; }
.modal__title {
  font-family: var(--mono);
  margin: .2rem 0 .5rem;
  font-size: 1.15rem;
}
.modal__body { margin: 0 0 1.2rem; color: var(--ink-soft); font-size: .92rem; }
.modal__actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* --- colophon ------------------------------------------------------------ */

.colophon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: 1.5rem 1.25rem 2.5rem;
  color: var(--ink-faint);
  font-size: .78rem;
}
.colophon [aria-hidden] { font-family: var(--mono); color: var(--stroke-soft); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
