/* MARKWRIGHT — styles.css
   The Lab level chrome (dark, retro-arcade) plus a calm editorial editor +
   preview surface. Press Start 2P is reserved for display chrome; the working
   editor and rendered document use system + mono stacks for readability. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --control-line: #5e5e80;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(14px, 4vw, 40px);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(69, 240, 255, 0.3); }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

/* ---------- header ---------- */

.site-header {
  position: relative;
  padding: 22px var(--space-gutter) 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.site-header [data-i18n-toggle] {
  position: absolute;
  top: 22px;
  right: var(--space-gutter);
}

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  position: relative;
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(20px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}

/* subtle glitch echo on the wordmark, disabled for reduced motion */
.wordmark::before,
.wordmark::after {
  content: attr(data-glitch);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  overflow: hidden;
  opacity: 0.7;
  pointer-events: none;
}
.wordmark::before { color: var(--cyan); clip-path: inset(0 0 55% 0); animation: glitch-a 3.6s steps(2) infinite; }
.wordmark::after { color: var(--magenta); clip-path: inset(55% 0 0 0); animation: glitch-b 4.1s steps(2) infinite; }
@keyframes glitch-a { 0%, 92%, 100% { transform: translate(0); } 94% { transform: translate(-2px, 1px); } 96% { transform: translate(2px, -1px); } }
@keyframes glitch-b { 0%, 90%, 100% { transform: translate(0); } 93% { transform: translate(2px, -1px); } 97% { transform: translate(-2px, 1px); } }

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}
.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

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

main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px var(--space-gutter) 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* ---------- command bar ---------- */

.command-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.cmd-spacer { flex: 1 1 auto; }
.cmd-group { display: flex; flex-wrap: wrap; gap: 6px; }

/* segmented view switch */
.cmd-view .seg + .seg { margin-left: -1px; }
.seg {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.seg:first-child { border-radius: 8px 0 0 8px; }
.seg:last-child { border-radius: 0 8px 8px 0; }
.seg:hover { color: var(--text); }
.seg.is-active {
  color: #05050d;
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
  z-index: 1;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 9px 12px;
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s, background 0.12s;
}
.btn:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(69, 240, 255, 0.22);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-ghost { background: transparent; }
.btn-ghost.is-active {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.35);
}

/* ---------- formatting toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tool {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.1s;
}
.tool:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(69, 240, 255, 0.2);
  transform: translateY(-1px);
}
.tool:active { transform: translateY(0); }
.tool strong, .tool em, .tool s { font-size: 15px; }

.tool-sep {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 3px;
}

.mobile-toggle { display: none; margin-left: auto; }

/* ---------- workspace (editor | preview) ---------- */

.workspace {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-height: clamp(360px, 60vh, 760px);
  flex: 1;
}
/* Editor-only / preview-only collapse is a DESKTOP behaviour. On mobile the
   workspace always stacks to a single pane controlled by .show-preview, so
   these single-column hide rules must not apply below the breakpoint —
   otherwise a persisted data-view="preview" would hide BOTH panes (blank). */
@media (min-width: 821px) {
  .workspace[data-view="editor"] { grid-template-columns: 1fr; }
  .workspace[data-view="editor"] .pane-divider,
  .workspace[data-view="editor"] .pane-preview { display: none; }
  .workspace[data-view="preview"] { grid-template-columns: 1fr; }
  .workspace[data-view="preview"] .pane-divider,
  .workspace[data-view="preview"] .pane-editor { display: none; }
}

.pane { display: flex; min-width: 0; min-height: 0; }
.pane-divider { background: var(--line); }

.editor-input {
  flex: 1;
  width: 100%;
  resize: none;
  border: 0;
  background: linear-gradient(180deg, rgba(26, 26, 42, 0.35), transparent 80px), var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  padding: 20px clamp(16px, 2.4vw, 28px);
  tab-size: 2;
  -moz-tab-size: 2;
  caret-color: var(--cyan);
  outline: none;
}
.editor-input:focus-visible { box-shadow: inset 0 0 0 2px rgba(69, 240, 255, 0.4); }
.editor-input::placeholder { color: var(--dim); opacity: 0.7; }

.preview-scroll {
  flex: 1;
  overflow: auto;
  background: var(--surface);
}
.preview-scroll:focus-visible { box-shadow: inset 0 0 0 2px rgba(69, 240, 255, 0.4); }

/* ---------- rendered document typography ---------- */

.preview {
  max-width: 72ch;
  margin: 0 auto;
  padding: 24px clamp(18px, 3vw, 40px) 64px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  word-wrap: break-word;
}
.preview > :first-child { margin-top: 0; }

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  line-height: 1.25;
  margin: 1.6em 0 0.55em;
  font-weight: 700;
  color: #fff;
}
.preview h1 {
  font-size: 1.9rem;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.3em;
}
.preview h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.25em;
}
.preview h3 { font-size: 1.25rem; color: var(--cyan); }
.preview h4 { font-size: 1.08rem; }
.preview h5 { font-size: 0.98rem; }
.preview h6 { font-size: 0.88rem; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }

.preview p { margin: 0 0 1.05em; }
.preview a { color: var(--cyan); text-decoration: none; border-bottom: 1px solid rgba(69, 240, 255, 0.35); }
.preview a:hover { border-bottom-color: var(--cyan); text-shadow: var(--glow-cyan); }
.preview strong { color: #fff; font-weight: 700; }
.preview em { font-style: italic; }
.preview del { color: var(--dim); }

.preview ul, .preview ol { margin: 0 0 1.05em; padding-left: 1.6em; }
.preview li { margin: 0.3em 0; }
.preview li > ul, .preview li > ol { margin: 0.3em 0; }
.preview ul.contains-task { list-style: none; padding-left: 0.2em; }
.preview li.task-item { display: flex; align-items: flex-start; gap: 0.55em; list-style: none; }
.preview li.task-item input[type="checkbox"] { margin-top: 0.42em; accent-color: var(--green); width: 15px; height: 15px; }

.preview blockquote {
  margin: 0 0 1.1em;
  padding: 0.5em 1.1em;
  border-left: 3px solid var(--magenta);
  background: rgba(255, 61, 139, 0.07);
  color: var(--dim);
  border-radius: 0 8px 8px 0;
}
.preview blockquote p:last-child { margin-bottom: 0; }

.preview code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  color: var(--gold);
}

.preview pre {
  margin: 0 0 1.2em;
  padding: 16px 18px;
  background: #0c0c16;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
  line-height: 1.55;
  position: relative;
}
.preview pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
}
.preview pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.86em;
  color: #d7d7e6;
}
.preview .tok-kw { color: var(--magenta); }
.preview .tok-str { color: var(--green); }
.preview .tok-com { color: var(--dim); font-style: italic; }
.preview .tok-num { color: var(--cyan); }

.preview hr {
  border: 0;
  border-top: 2px solid var(--line);
  margin: 2em 0;
}

.preview img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.2em;
  font-size: 0.95em;
  overflow: hidden;
  border-radius: 8px;
}
.preview th, .preview td {
  border: 1px solid var(--line);
  padding: 0.5em 0.8em;
  text-align: left;
}
.preview th { background: var(--surface-2); color: #fff; font-weight: 700; }
.preview tbody tr:nth-child(even) td { background: rgba(26, 26, 42, 0.4); }

/* ---------- stat bar ---------- */

.statbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}
.statbar strong { color: var(--gold); font-weight: 700; }
.stat-dot { color: var(--line); }
#statRead { color: var(--cyan); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--cyan);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 20px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */

/* On narrow screens the workspace stacks; a toggle swaps editor/preview. */
@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; }
  .pane-divider { display: none; }
  /* default mobile view is the editor; reassert it even when a persisted
     data-view="preview"/"editor" is still on the element */
  .workspace .pane-editor { display: flex; }
  .pane-preview { display: none; }
  .workspace.show-preview .pane-editor { display: none; }
  .workspace.show-preview .pane-preview { display: flex; }
  /* the segmented view switch is replaced by the mobile toggle */
  .cmd-view { display: none; }
  .mobile-toggle { display: inline-flex; }
  /* force a usable stacked height */
  .workspace { min-height: clamp(320px, 56vh, 600px); }
}

@media (max-width: 560px) {
  .command-bar { gap: 8px; }
  .cmd-export { width: 100%; justify-content: stretch; }
  .cmd-export .btn { flex: 1 1 auto; font-size: 10.5px; padding: 9px 8px; }
  .cmd-doc { width: 100%; }
  .cmd-doc .btn { flex: 1 1 auto; }
  .preview { font-size: 15px; padding: 18px 16px 48px; }
  .editor-input { font-size: 13.5px; padding: 16px; }
}

/* coarse pointers get larger hit targets */
@media (pointer: coarse) {
  .tool { width: 44px; height: 44px; }
  .seg { padding: 10px 14px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
  .wordmark::before, .wordmark::after { display: none; }
}
