/* GoodNotes-Klon im DND-Art-Style – Variablen 1:1 aus DND-Character-sheet-generator */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf6ee;
  --bg-image: url('../altes_Papier.png');
  --text: #2a1a0e;
  --accent: #8b5a2b;
  --accent-dark: #654321;
  --accent-muted: #5c3a1e;
  --border: #c9a87c;
  --border-light: #e5d5c0;
  --surface: rgba(250, 246, 238, 0.8);
  --surface-strong: rgba(240, 232, 213, 0.82);
  --field-bg: rgba(250, 246, 238, 0.6);
  --disabled-bg: rgba(240, 232, 213, 0.7);
  --button-bg: #8b5a2b;
  --button-text: #faf6ee;
  --button-inactive-bg: rgba(240, 232, 213, 0.8);
  --button-inactive-text: #5c3a1e;
  --mini-button-hover-bg: rgba(230, 214, 191, 0.8);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1410;
    --bg-image: linear-gradient(rgba(27, 20, 16, 0.8), rgba(27, 20, 16, 0.8)), url('../altes_Papier.png');
    --text: #f3e9db;
    --accent: #d6a670;
    --accent-dark: #b07b46;
    --accent-muted: #d1b38f;
    --border: #6a4a31;
    --border-light: #3d2b1d;
    --surface: rgba(34, 25, 19, 0.85);
    --surface-strong: rgba(44, 32, 24, 0.85);
    --field-bg: rgba(55, 41, 30, 0.6);
    --disabled-bg: rgba(55, 41, 30, 0.45);
    --button-bg: #7a5332;
    --button-text: #f9f1e7;
    --button-inactive-bg: rgba(60, 44, 32, 0.7);
    --button-inactive-text: #d3b89a;
    --mini-button-hover-bg: rgba(86, 61, 43, 0.7);
  }
}

body { font-family: 'Crimson Text', serif; background-color: var(--bg); background-image: var(--bg-image); color: var(--text); padding: 20px; }
.container { max-width: 1100px; margin: 0 auto; }

.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.header h1 { font-family: 'Cinzel', serif; font-size: 26px; color: var(--accent); letter-spacing: 2px; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.version-tag { font-family: 'Cinzel', serif; font-size: 9px; color: var(--accent-muted); align-self: center; padding: 0 4px; letter-spacing: 1px; }

button { font-family: 'Cinzel', serif; font-size: 12px; padding: 8px 16px; background: var(--button-bg); color: var(--button-text); border: 2px solid var(--accent); cursor: pointer; transition: background 0.2s; }
button:hover { background: var(--accent-dark); }
button.inactive { background: var(--button-inactive-bg); color: var(--button-inactive-text); }

.box { border: 2px solid var(--accent); background: var(--surface); padding: 15px; margin-bottom: 15px; }

label { font-family: 'Cinzel', serif; font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 4px; }
input[type="text"], input[type="number"], input[type="color"], input[type="range"], textarea, select { font-family: 'Crimson Text', serif; font-size: 14px; color: var(--text); background: var(--field-bg); border: none; border-bottom: 1px solid var(--border); padding: 4px 6px; width: 100%; outline: none; }
input[type="color"] { padding: 0; height: 30px; border: 1px solid var(--border); cursor: pointer; }
input:disabled { background: var(--disabled-bg); cursor: not-allowed; opacity: 0.8; }

.mini-button { font-family: 'Cinzel', serif; font-size: 10px; padding: 4px 8px; background: var(--surface-strong); color: var(--accent-muted); border: 1px solid var(--border); cursor: pointer; transition: background 0.2s; }
.mini-button:hover { background: var(--mini-button-hover-bg); }
.mini-button:disabled { opacity: 0.6; cursor: not-allowed; }
.mini-button.picked { background: var(--accent); color: var(--button-text); border-color: var(--accent); }

.divider { display: flex; align-items: center; gap: 6px; margin: 12px 0 8px; }
.divider-line { flex: 1; border-top: 1px solid var(--border); }
.divider-title { font-family: 'Cinzel', serif; font-size: 9px; color: var(--accent); letter-spacing: 1px; text-transform: uppercase; white-space: nowrap; }

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; }

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }

/* ===== Bibliothek ===== */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.notebook-cover { border: 2px solid var(--accent); background: var(--surface-strong); cursor: pointer; padding: 0; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.notebook-cover:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.notebook-spine { height: 10px; background: linear-gradient(135deg, var(--accent-dark), var(--accent)); }
.notebook-body { padding: 14px 12px; min-height: 150px; display: flex; flex-direction: column; gap: 6px; }
.notebook-title { font-family: 'Cinzel', serif; font-size: 15px; font-weight: bold; color: var(--accent); line-height: 1.25; word-break: break-word; }
.notebook-meta { font-size: 12px; color: var(--accent-muted); }
.notebook-preview { font-size: 12px; opacity: .8; font-style: italic; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.notebook-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }

/* ===== Arbeitsbereich ===== */
.work-layout { display: grid; grid-template-columns: 170px 1fr; gap: 12px; align-items: start; }
.page-rail { display: flex; flex-direction: column; gap: 8px; max-height: 78vh; overflow-y: auto; padding-right: 2px; }
.page-thumb { border: 2px solid var(--border); background: var(--surface-strong); cursor: pointer; padding: 6px; text-align: center; font-size: 11px; }
.page-thumb.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.page-thumb canvas { width: 100%; height: auto; display: block; background: #fffdf6; border: 1px solid var(--border-light); }
.page-thumb .thumb-label { font-family: 'Cinzel', serif; font-size: 9px; color: var(--accent); margin-top: 4px; }

.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar .sep { border-left: 1px solid var(--border); height: 22px; margin: 0 2px; }
.tool-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tool-group input[type="color"] { width: 38px; }
.tool-group input[type="range"] { width: 90px; accent-color: var(--accent); }

.stage-wrap { display: flex; justify-content: center; }
.stage { position: relative; width: 100%; max-width: 760px; aspect-ratio: 1 / 1.294; background-color: #fffdf6; background-image: var(--bg-image); background-blend-mode: multiply; border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--surface-strong), 0 14px 34px rgba(0,0,0,.3); overflow: hidden; touch-action: none; }
.stage.lined { background-image: linear-gradient(transparent 95%, var(--border-light) 100%), var(--bg-image); background-size: 100% 32px, auto; }
.stage.grid { background-image: linear-gradient(var(--border-light) 1px, transparent 1px), linear-gradient(90deg, var(--border-light) 1px, transparent 1px), var(--bg-image); background-size: 24px 24px, 24px 24px, auto; }
#drawCanvas, #overlayCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#drawCanvas { z-index: 2; }
#overlayCanvas { z-index: 3; pointer-events: none; }
.text-layer, .img-layer { position: absolute; inset: 0; z-index: 4; }
.text-layer { pointer-events: none; }
.text-box { position: absolute; min-width: 80px; min-height: 30px; padding: 4px 6px; font-size: 17px; line-height: 1.4; border: 1px dashed transparent; cursor: text; pointer-events: auto; word-break: break-word; }
.text-box.selected { border-color: var(--accent); background: rgba(250,246,238,.5); }
.text-box h1 { font-family: 'Cinzel', serif; color: var(--accent); font-size: 24px; }
.text-box h2 { font-family: 'Cinzel', serif; color: var(--accent); font-size: 20px; }
.text-box h3 { font-family: 'Cinzel', serif; color: var(--accent); font-size: 17px; }
.img-item { position: absolute; border: 1px dashed transparent; pointer-events: auto; }
.img-item.selected { border-color: var(--accent); }
.img-item img { width: 100%; height: 100%; display: block; }
.img-handle { position: absolute; right: -10px; bottom: -10px; width: 20px; height: 20px; background: var(--accent); color: var(--button-text); font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: nwse-resize; border-radius: 50%; }

.status-line { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--accent-muted); margin-top: 8px; }

/* ===== Texteditor-Overlay (1:1 aus DND übernommen) ===== */
.editor-overlay { position: fixed; inset: 0; background: rgba(15, 10, 5, 0.75); backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center; z-index: 9999; padding: 15px; }
.editor-overlay.active { display: flex; }
.editor-modal { background-color: var(--bg); background-image: var(--bg-image); border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--surface-strong), 0 20px 50px rgba(0,0,0,0.6); width: 100%; max-width: 820px; max-height: 90vh; display: flex; flex-direction: column; border-radius: 4px; overflow: hidden; }
.editor-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 2px solid var(--accent); background: var(--surface); }
.editor-header-title { font-family: 'Cinzel', serif; font-size: 16px; color: var(--accent); letter-spacing: 2px; font-weight: bold; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; background: var(--surface-strong); border-bottom: 1px solid var(--border); align-items: center; }
.editor-select { width: auto; padding: 4px 8px; font-family: 'Cinzel', serif; font-size: 11px; border: 1px solid var(--border); background: var(--field-bg); color: var(--text); cursor: pointer; }
.editor-sep { border-left: 1px solid var(--border); height: 18px; margin: 0 2px; }
.editor-body { flex: 1; min-height: 280px; max-height: 55vh; overflow-y: auto; padding: 16px; font-family: 'Crimson Text', serif; font-size: 16px; line-height: 1.5; color: var(--text); background: var(--field-bg); outline: none; border: none; white-space: pre-wrap; word-break: break-word; }
.editor-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border-light); }
.rich-field h1, .editor-body h1, .rich-field h2, .editor-body h2, .rich-field h3, .editor-body h3 { font-family: 'Cinzel', serif; color: var(--accent); margin: 4px 0 2px; line-height: 1.2; }
.rich-field h1, .editor-body h1 { font-size: 20px; }
.rich-field h2, .editor-body h2 { font-size: 17px; }
.rich-field h3, .editor-body h3 { font-size: 15px; }

@media (max-width: 860px) {
  body { padding: 10px; }
  .header h1 { font-size: 20px; }
  button { padding: 7px 10px; font-size: 11px; }
  .work-layout { grid-template-columns: 1fr; }
  .page-rail { flex-direction: row; max-height: none; overflow-x: auto; }
  .page-thumb { min-width: 110px; }
}

@media print {
  body { background: #fff; padding: 0; }
  .header, .toolbar, .page-rail, .buttons, .status-line, .no-print { display: none !important; }
  .container { max-width: none; }
  .stage { box-shadow: none; max-width: none; border: 1px solid #999; }
}
