:root {
  --bg: #f4f2ec;
  --panel: #fffefb;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e4e0d6;
  --accent: #2b4acb;
  --accent-ink: #fff;
  --ok: #1d7a46;
  --warn: #9a5b00;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 30, 20, 0.06), 0 6px 24px rgba(30, 30, 20, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

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

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: rgba(244, 242, 236, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.app-version { font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.tabs { display: flex; gap: 4px; background: #e9e6dd; padding: 4px; border-radius: 999px; margin-left: auto; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; color: #4b5161; white-space: nowrap;
}
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

main { padding: 18px 20px 40px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* ------------------------------------------------------------ generic */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.panel h3 { margin: 18px 0 6px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.wide { width: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid #d6d1c4; background: #fff; cursor: pointer; font-weight: 600;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:hover { border-color: #b9b2a1; }
.btn:active { transform: translateY(1px); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary small { font-weight: 500; opacity: .85; font-size: 11px; }
.btn.danger { color: var(--danger); border-color: #e7c2bf; }
.btn.needs-setup { background: #fff; color: var(--accent); }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }

.check { display: flex; gap: 8px; align-items: center; cursor: pointer; margin-top: 10px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ------------------------------------------------------------ controls */
.write-layout { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.controls { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
.field { margin-top: 12px; }
.field > label, .field .label { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: #3d4352; margin-bottom: 5px; }
.field output { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
textarea {
  width: 100%; resize: vertical; min-height: 130px; padding: 10px 12px;
  border: 1px solid #d6d1c4; border-radius: 10px; background: #fff; line-height: 1.5;
}
.input { width: 100%; min-height: 40px; padding: 0 12px; border: 1px solid #d6d1c4; border-radius: 10px; background: #fff; }
.hint { margin: 6px 0 0; }
select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid #d6d1c4; border-radius: 10px; background: #fff; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
details { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
summary { cursor: pointer; font-weight: 700; font-size: 14px; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 32px; }
summary::after { content: "▾"; color: var(--muted); }
details:not([open]) summary::after { content: "▸"; }
summary::-webkit-details-marker { display: none; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button, .swatch-custom {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(0,0,0,.18);
  background: var(--c); cursor: pointer; padding: 0; position: relative;
}
.swatches button.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-custom { background: conic-gradient(#e53, #ec3, #3c5, #3be, #63e, #e3a, #e53); overflow: hidden; display: inline-block; }
.swatch-custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.segmented { display: flex; background: #eeebe3; border-radius: 10px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: transparent; min-height: 34px; border-radius: 8px; font-weight: 600; cursor: pointer; color: #4b5161; }
.segmented button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.presets button { border: 1px solid #e0dccf; background: #fff; min-height: 34px; border-radius: 8px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; color: #4b5161; padding: 0 2px; }
.presets button.on { border-color: var(--accent); outline: 1px solid var(--accent); color: var(--ink); }

/* ------------------------------------------------------------ preview */
.preview-col { min-width: 0; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.export { display: flex; gap: 8px; flex-wrap: wrap; }
.pages { display: flex; flex-direction: column; gap: 18px; max-width: 860px; }
.page { display: block; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 30px rgba(40,35,20,.10); background: #fff; }
.notice { background: #fff7e6; border: 1px solid #f0d9a8; color: #6b4a00; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; line-height: 1.9; }
.chip { border: 1px solid #e3c98a; background: #fff; border-radius: 6px; min-width: 28px; height: 28px; cursor: pointer; font-weight: 700; }

/* ------------------------------------------------------------ font editor */
.font-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.editor { max-width: 760px; }
.font-mode { max-width: 360px; margin-bottom: 10px; }
.font-mode-hint { margin: -2px 0 10px; }
.editor-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.cur-char {
  flex: none; width: 64px; height: 64px; border-radius: 14px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 36px; font-weight: 600;
}
.editor-head p { margin: 0; }
.pad-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
#pad { display: block; width: 100%; aspect-ratio: 1 / 1; max-height: 64vh; touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; }
.editor-actions { flex-wrap: wrap; }
.editor-actions .btn { min-height: 46px; }
.variants { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.variant { position: relative; }
.variant canvas { width: 88px; height: 88px; border: 1px solid var(--line); border-radius: 10px; display: block; background: #fff; }
.variant-del {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid #ddd; background: #fff; cursor: pointer; font-size: 16px; line-height: 1; color: var(--danger);
}
.charset-panel h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.charset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 5px; }
.char {
  position: relative; height: 40px; border-radius: 8px; border: 1px solid #ddd8cb; background: #fff;
  font-size: 18px; cursor: pointer; padding: 0;
}
.char.partial { background: #fff6dc; border-color: #ecd69a; }
.char.done { background: #e5f4ea; border-color: #a9d8b8; }
.char.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.char i { position: absolute; right: 3px; bottom: 1px; font-size: 10px; font-style: normal; color: var(--muted); }
.progress { position: relative; font-size: 14px; padding-bottom: 10px; }
.progress::after { content: ""; display: block; height: 6px; border-radius: 3px; margin-top: 6px; background: linear-gradient(90deg, var(--ok) var(--p, 0%), #e8e4da var(--p, 0%)); }

/* ------------------------------------------------------------ goodnotes */
.gn-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; max-width: 1100px; }
.steps { padding-left: 20px; }
.steps li { margin: 6px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }
.warn { background: #fff7e6; border: 1px solid #f0d9a8; color: #6b4a00; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.gn-list { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.gn-list:empty::before { content: "Noch keine Vorlage geladen."; color: var(--muted); font-size: 14px; }
.gn-item { border: 1px solid #e4dfd3; border-radius: 12px; padding: 10px 12px; background: #fff; display: grid; gap: 6px; }
.gn-item.is-default { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.gn-item-head { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 8px; }
.gn-name { min-height: 40px; padding: 0 10px; border: 1px solid #d6d1c4; border-radius: 10px; font-weight: 600; min-width: 0; }
.gn-item-meta { font-size: 13px; }
.gn-item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.gn-item .warn { margin: 0; }
.gn-export { display: inline-flex; gap: 8px; }
.gn-pick { width: auto; max-width: 170px; min-height: 40px; font-size: 14px; }
code { background: #efece4; padding: 2px 5px; border-radius: 5px; font-size: 12px; word-break: break-all; }

/* ------------------------------------------------------------ toast */
#toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: min(560px, 92vw);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast[data-kind="error"] { background: var(--danger); }
#toast[data-kind="ok"] { background: var(--ok); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .write-layout { grid-template-columns: 290px 1fr; gap: 14px; }
  .font-layout { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 980px) {
  .font-layout, .gn-layout { grid-template-columns: minmax(0, 1fr); }
  .font-layout > *, .gn-layout > * { min-width: 0; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1; padding: 7px 10px; }
  main { padding: 14px 12px 40px; }
}
@media (max-width: 700px) {
  .write-layout { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; }
}

/* ------------------------------------------------------------ account / cloud sync */
.account { display: flex; align-items: center; gap: 10px; }
.account-btn svg { width: 18px; height: 18px; }
.sync-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync-status[data-state="ok"] { color: var(--ok); }
.sync-status[data-state="offline"], .sync-status[data-state="error"] { color: var(--warn); }
.cloud-dialog {
  border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 24px));
  background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(20, 20, 10, 0.25);
}
.cloud-dialog::backdrop { background: rgba(20, 24, 33, 0.35); }
.cloud-form { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.cloud-form h2 { margin: 0; font-size: 20px; }
.cloud-form p { margin: 0; }
.cloud-field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.cloud-field input {
  min-height: 44px; padding: 0 12px; border: 1px solid #d6d1c4; border-radius: 10px; background: #fff; font-size: 16px;
}
.cloud-msg:empty { display: none; }
.cloud-msg { font-size: 14px; }
.cloud-msg[data-kind="error"] { color: var(--danger); }
.cloud-msg[data-kind="ok"] { color: var(--ok); }
.cloud-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cloud-actions .btn { min-height: 44px; }
.cloud-actions.between { justify-content: space-between; margin-top: 4px; }
.cloud-choices { display: flex; flex-direction: column; gap: 8px; }
.cloud-choices .btn { flex-direction: column; min-height: 54px; gap: 2px; }
.cloud-choices .btn small { font-weight: 500; font-size: 12px; opacity: .8; }
@media (max-width: 980px) {
  .brand { order: 0; }
  .account { order: 1; margin-left: auto; }
  .tabs { order: 2; }
}
@media (max-width: 560px) {
  .sync-status { display: none; }
  .tabs { flex-wrap: wrap; border-radius: 18px; }
  .tabs button { font-size: 13px; padding: 7px 8px; }
}

/* ------------------------------------------------------------ Tour (Rundgang, js/tour.js) */
.tour { position: fixed; inset: 0; z-index: 100; }
.tour-block { position: absolute; inset: 0; }
.tour-spot {
  position: fixed; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(20, 24, 36, 0.62);
  transition: left .25s, top .25s, width .25s, height .25s;
}
.tour-card {
  position: fixed; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow: auto;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); outline: none;
}
.tour-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.tour-title { margin: 2px 0 6px; font-size: 18px; }
.tour-text { margin: 0 0 10px; }
.tour-dots { display: flex; gap: 6px; margin-bottom: 12px; }
.tour-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.tour-dots span.on { background: var(--accent); }
.tour-actions { display: flex; align-items: center; gap: 8px; }
.tour-actions .btn { min-height: 40px; }
.tour-calm .tour-spot { transition: none; }
@media (prefers-reduced-motion: reduce) { .tour-spot { transition: none; } }
.site-footer { text-align: center; padding: 0 20px 28px; font-size: 13px; color: var(--muted); }
.site-footer a { color: var(--accent); }
