/* Editor chrome only.
 *
 * The writing surface itself is styled from src/shared/css.js at runtime — the
 * same module the exporter uses. Nothing here may set typography, width or
 * padding on #editor, or the preview stops telling the truth (CLAUDE.md #4).
 *
 * Chrome colours are mixed from the document's own colours, so the interface
 * stays still whatever look the user picks (§12.1). One material — the page —
 * and hairlines mixed from its own ink. No shadows, no second surface. */

:root {
  --chrome-fg: color-mix(
    in srgb,
    var(--qt-fg, #232120) 72%,
    var(--chrome-base, #f5f1e9)
  );
  --chrome-fg-strong: var(--qt-fg, #232120);
  --chrome-line: color-mix(
    in srgb,
    var(--qt-fg, #232120) 14%,
    var(--chrome-base, #f5f1e9)
  );
  --chrome-hover: color-mix(
    in srgb,
    var(--qt-fg, #232120) 7%,
    var(--chrome-base, #f5f1e9)
  );
  --chrome-press: color-mix(
    in srgb,
    var(--qt-fg, #232120) 13%,
    var(--chrome-base, #f5f1e9)
  );
  --chrome-accent: color-mix(
    in srgb,
    var(--qt-fg, #232120) 55%,
    var(--chrome-base, #f5f1e9)
  );
  --chrome-radius: 4px;
  --chrome-font:
    system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP",
    "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

/* #stage paints the static fallback when the living background is off. Keeping
   the root clear lets the shader reveal the transparent BrowserWindow. */
html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: transparent;
}

body {
  font-family: var(--chrome-font);
  color: var(--chrome-fg);
  -webkit-user-select: none;
  user-select: none;
}

/* A WebGL wash sits behind the document. The CSS background is also the
   no-WebGL fallback; neither layer receives input or enters exported HTML. */
#shader-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0.38;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 16%, #5c8798 0%, transparent 42%),
    radial-gradient(circle at 84% 74%, #b96c59 0%, transparent 46%),
    linear-gradient(145deg, #172734, #6c746b 52%, #713f43);
}

/* -------------------------------------------------------------- titlebar */

/* Windows runs without a title bar (§12.1); this invisible strip is what the
   window is dragged by. Anything interactive near the top opts out below. */
#titlebar {
  display: none;
}

.frameless #titlebar {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 138px;
  height: 34px;
  z-index: 5;
  -webkit-app-region: drag;
}

#window-controls {
  display: none;
}

.frameless #window-controls {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  display: flex;
  height: 34px;
  -webkit-app-region: no-drag;
}

#window-controls button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--chrome-fg-strong);
  opacity: 0.5;
  cursor: default;
}

#window-controls button:hover,
#window-controls button:focus-visible {
  background: var(--chrome-hover);
  opacity: 1;
}

#window-controls .window-control--close:hover,
#window-controls .window-control--close:focus-visible {
  background: #c42b1c;
  color: #fff;
}

#window-controls svg {
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  shape-rendering: crispEdges;
}

/* All persistent actions share one still home. Browser-only file commands
   disappear in Electron, leaving hand-over and settings in the same shell. */
#app-actions {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--chrome-base, #f5f1e9) 78%, transparent);
  opacity: 0.3;
  transition: opacity 160ms ease;
  -webkit-app-region: no-drag;
}

#app-actions:hover,
#app-actions:focus-within {
  opacity: 1;
}

body.actions-hidden #app-actions {
  display: none;
}

.frameless #app-actions {
  top: 1px;
  left: 4px;
  padding: 1px 3px;
}

#web-actions {
  display: flex;
  gap: 2px;
}

#web-actions[hidden] {
  display: none;
}

#app-actions button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--chrome-radius);
  background: transparent;
  color: var(--chrome-fg-strong);
  cursor: pointer;
  touch-action: manipulation;
}

/* Touch pointers need a bigger target than a mouse cursor does (NFR-401). */
@media (pointer: coarse) {
  #app-actions {
    opacity: 1;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
  }

  #app-actions button {
    width: 42px;
    height: 42px;
  }

  #app-actions svg {
    width: 20px;
    height: 20px;
  }
}

#app-actions button:hover,
#app-actions button:focus-visible {
  background: var(--chrome-hover);
}

#app-actions svg {
  width: 16px;
  height: 16px;
}

#web-actions svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#panel,
#find,
#overlay,
.edge-handle {
  -webkit-app-region: no-drag;
}

/* ---------------------------------------------------------------- surface */

#stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  transition: right 180ms ease;
}

/* The drawer makes room for itself rather than sitting on top of the writing —
   the point is to see the change as you make it (FR-102). */
body.panel-open #stage {
  right: 336px;
}

@media (max-width: 860px) {
  body.panel-open #stage {
    right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #stage {
    transition: none;
  }
}

#page {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow: hidden;
}

#editor {
  display: block;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  -webkit-user-select: text;
  user-select: text;
  /* The caret is drawn by caret.js so its thickness can be changed (FR-109). */
  caret-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: var(--chrome-line) transparent;
}

/* While an IME is composing, Chromium owns the caret; ours would sit in the
   wrong place, so we hand it back (see caret.js). */
#editor.native-caret {
  caret-color: var(--qt-caret, currentColor);
}

#editor::selection {
  background: var(--qt-selection-bg, #d9d2c4);
  color: var(--qt-selection-fg, inherit);
}

/* Measurement copy of the text, never visible. */
#mirror {
  position: absolute;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  height: 100%;
}

/* An auto-height copy used only to measure how much of one screen the writing
   occupies. Unlike #mirror, it must not be forced to the viewport height. */
#text-amount-measure {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  height: auto;
  min-height: 0;
  overflow: visible;
}

#caret {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--qt-caret-width, 2px);
  background: var(--qt-caret, currentColor);
  border-radius: 1px;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(0, 0, 0);
}

#caret.on {
  opacity: 1;
}

#caret.blink {
  animation: caret-blink var(--qt-caret-blink, 530ms) steps(1, end) infinite;
}

@keyframes caret-blink {
  0%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #caret.blink {
    animation: none;
  }
  * {
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------- direct handles */

/* The drag targets of FR-502, with nothing drawn (§19.1): the pointer shape
   and the HUD readout are the only signs they exist. Keyboard focus still
   gets an outline. */
.edge-handle {
  position: absolute;
  z-index: 3;
  background: transparent;
}

.edge-handle {
  top: 50%;
  width: 10px;
  height: 72px;
  margin-top: -36px;
  cursor: ew-resize;
  touch-action: none;
}

.edge-handle:focus-visible {
  outline: 2px solid var(--chrome-fg-strong);
  outline-offset: 1px;
}

@media (pointer: coarse) {
  .edge-handle {
    width: 28px;
    height: 96px;
    margin-top: -48px;
  }
}

#hud {
  position: fixed;
  z-index: 20;
  padding: 5px 9px;
  border-radius: var(--chrome-radius);
  background: var(--chrome-fg-strong);
  color: var(--chrome-base, #fff);
  font-size: 12px;
  letter-spacing: 0.01em;
  pointer-events: none;
  white-space: nowrap;
}

/* ------------------------------------------------------------- status */

#status {
  position: fixed;
  z-index: 4;
  left: 16px;
  bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--chrome-fg);
  opacity: 0.5;
  transition: opacity 400ms ease;
  pointer-events: none;
  max-width: 50vw;
}

#status.still {
  opacity: 0;
}

#status-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status-state {
  opacity: 0.75;
}

/* -------------------------------------------------------------- panel */

#panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 336px;
  max-width: 92vw;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--chrome-base, #f5f1e9);
  border-left: 1px solid var(--chrome-line);
  overflow: hidden;
}

#panel[hidden] {
  display: none;
}

.panel-head {
  padding: 20px 22px 4px;
}

/* Leave the top-right corner to the Windows window buttons. */
.frameless .panel-head {
  padding-top: 44px;
}

.panel-head h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--chrome-fg-strong);
}

.panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--chrome-radius);
  background: transparent;
  color: var(--chrome-fg);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
}

.frameless .panel-close {
  top: 40px;
}

.panel-close:hover {
  opacity: 1;
  background: var(--chrome-hover);
}

@media (pointer: coarse) {
  .panel-close {
    width: 40px;
    height: 40px;
  }
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 22px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--chrome-line) transparent;
}

/* Groups are separated by air, not lines. */
.group {
  padding: 22px 0 0;
}

.group > h2 {
  margin: 0 0 12px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  opacity: 0.45;
}

.group > .note {
  margin: -6px 0 12px;
  font-size: 11.5px;
  line-height: 1.5;
  opacity: 0.55;
}

.row {
  margin-bottom: 13px;
}

.row-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}

.row-head label {
  font-size: 12.5px;
  color: var(--chrome-fg-strong);
}

.row-head .value {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--chrome-accent);
  height: 18px;
}

input[type="number"],
input[type="text"],
select {
  width: 68px;
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
  color: var(--chrome-fg-strong);
  background: var(--chrome-hover);
  border: 0;
  border-radius: var(--chrome-radius);
  font-variant-numeric: tabular-nums;
}

select,
input[type="text"] {
  width: 100%;
}

input[type="color"] {
  width: 36px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--chrome-line);
  border-radius: var(--chrome-radius);
  background: transparent;
  cursor: pointer;
}

input:disabled,
select:disabled {
  opacity: 0.35;
  cursor: default;
}

/* iOS Safari zooms the page when a focused input's font is under 16px. */
@media (pointer: coarse) {
  input[type="number"],
  input[type="text"],
  select {
    font-size: 16px;
  }
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--chrome-fg-strong);
  outline-offset: 1px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--chrome-fg-strong);
  cursor: pointer;
}

.check input {
  accent-color: var(--chrome-accent);
}

.btn {
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--chrome-fg-strong);
  background: var(--chrome-hover);
  border: 0;
  border-radius: var(--chrome-radius);
  cursor: pointer;
}

.btn:hover {
  background: var(--chrome-press);
}

.btn--primary {
  background: var(--chrome-fg-strong);
  color: var(--chrome-base, #fff);
}

.btn--primary:hover {
  opacity: 0.88;
  background: var(--chrome-fg-strong);
}

/* Hand-over choices inside the preview dialog. */
.export-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 10px;
}

.export-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--chrome-fg-strong);
}

.export-row[hidden] {
  display: none;
}

.export-row select {
  width: auto;
}

.export-note {
  font-size: 11.5px;
  opacity: 0.65;
  margin: 0 0 10px;
}

.warning {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 8px 0 4px;
  padding: 2px 0 2px 10px;
  font-size: 11.5px;
  line-height: 1.45;
  border-left: 2px solid #c8860d;
  color: var(--chrome-fg-strong);
}

.warning button {
  flex: none;
}

/* --------------------------------------------------------------- find */

#find {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--chrome-base, #f5f1e9);
  border: 1px solid var(--chrome-line);
  min-width: 340px;
  max-width: calc(100vw - 24px);
}

@media (max-width: 400px) {
  #find {
    min-width: 0;
    width: calc(100vw - 24px);
  }
}

.frameless #find {
  top: 42px;
}

#find[hidden] {
  display: none;
}

.find-line {
  display: flex;
  gap: 6px;
  align-items: center;
}

.find-line input[type="text"] {
  flex: 1;
  width: auto;
}

.find-count {
  font-size: 11px;
  opacity: 0.65;
  min-width: 64px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ overlay */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 32px;
  background: color-mix(in srgb, var(--qt-fg, #000) 26%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(0.8);
  backdrop-filter: blur(10px) saturate(0.8);
  animation: overlay-in 150ms ease-out;
}

#overlay[hidden] {
  display: none;
}

.card {
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 18px;
  border-radius: 6px;
  background: var(--chrome-base, #f5f1e9);
  border: 1px solid var(--chrome-line);
  color: var(--chrome-fg);
  animation: card-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--chrome-fg-strong);
}

.card p {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.6;
}

.card--confirm,
.card--message,
.card--help {
  width: min(440px, 100%);
  padding: 27px 28px 22px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--chrome-base, #f5f1e9) 96%, transparent);
}

.dialog-intro {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 14px;
  align-items: start;
}

.dialog-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--chrome-line);
  border-radius: 50%;
  background: var(--chrome-hover);
}

.dialog-mark span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chrome-fg-strong);
  opacity: 0.72;
}

.dialog-copy {
  min-width: 0;
}

.dialog-body {
  white-space: pre-line;
}

.shortcut-list {
  display: grid;
  gap: 2px;
  margin: 4px 0 20px;
}

.shortcut-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid var(--chrome-line);
  font-size: 12.5px;
  color: var(--chrome-fg-strong);
}

.shortcut-row kbd {
  padding: 3px 7px;
  border: 1px solid var(--chrome-line);
  border-radius: 5px;
  background: var(--chrome-hover);
  font-family: var(--chrome-font);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.help-section {
  padding-top: 2px;
}

.help-section h3 {
  margin: 0 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--chrome-fg-strong);
  opacity: 0.6;
}

.help-about p {
  white-space: pre-line;
}

.card.card--confirm .actions,
.card.card--message .actions,
.card.card--help .actions {
  margin-top: 12px;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  #overlay,
  .card {
    animation: none;
  }
}

.card .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}

.card--preview {
  width: min(900px, 100%);
  height: min(78vh, 100%);
}

.preview-frame {
  flex: 1;
  width: 100%;
  border: 1px solid var(--chrome-line);
  border-radius: var(--chrome-radius);
  background: #fff;
  margin-bottom: 12px;
}

/* --------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 25;
  max-width: min(560px, 88vw);
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--chrome-base, #f5f1e9);
  border: 1px solid var(--chrome-line);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--chrome-fg-strong);
}

#toast[hidden] {
  display: none;
}

#toast.plain {
  padding: 7px 14px;
  opacity: 0.95;
}

/* First run: one sentence and a way in (FR-505). */
.welcome {
  display: flex;
  align-items: center;
  gap: 14px;
}

.welcome p {
  margin: 0;
}

.welcome .actions {
  flex: none;
}

@media (max-width: 480px) {
  .welcome {
    flex-direction: column;
    align-items: stretch;
  }
}
