/* ==========================================================================
   DM Notes — Phase 1 Stylesheet (D&D Parchment Theme)
   Modern + readable, but themed like a DM notebook:
   parchment paper, ink lines, wax accents, leather header.
   Usage:
   <link rel="stylesheet" href="/assets/css/app.css">
   ========================================================================== */

/* -----------------------------
   1) Design Tokens
------------------------------ */
:root {
  /* Layout */
  --max-w: 1180px;
  --gutter: 20px;

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --text-xs: 12px;
  --text-sm: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;

  --lh-tight: 1.25;
  --lh-normal: 1.5;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  /* Radius (slightly softer = paper) */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;

  /* Shadows (warmer) */
  --shadow-1: 0 10px 30px rgba(26, 20, 16, 0.10);
  --shadow-2: 0 14px 44px rgba(26, 20, 16, 0.14);

  /* Colors (Parchment Light) */
  --bg: #f3ead7;          /* parchment */
  --surface: rgba(255, 255, 255, 0.72);
  --surface-2: rgba(255, 255, 255, 0.55);
  --border: rgba(58, 45, 36, 0.20);
  --border-2: rgba(58, 45, 36, 0.30);

  --text: #2a2420;        /* ink */
  --muted: rgba(42, 36, 32, 0.70);

  /* Accents */
  --primary: #6b1f1f;     /* wax red */
  --primary-2: #8a2a2a;
  --danger: #7a2020;

  --ok: #2d6e41;          /* forest ink */
  --warn: #b38b3d;        /* brass */
  --info: #2c4a73;        /* ink blue */

  /* Focus ring */
  --ring: 0 0 0 4px rgba(179, 139, 61, 0.30);

  /* Inputs */
  --input-bg: rgba(255, 255, 255, 0.45);
  --input-border: rgba(58, 45, 36, 0.22);
  --input-border-hover: rgba(58, 45, 36, 0.34);

  /* Code-ish blocks */
  --code-bg: rgba(179, 139, 61, 0.12);
  --code-border: rgba(179, 139, 61, 0.30);
}

/* Optional dark mode (auto) — “Night DM” */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0d0b; /* near-black leather */
    --surface: rgba(26, 20, 16, 0.78);
    --surface-2: rgba(26, 20, 16, 0.62);
    --border: rgba(255, 255, 255, 0.10);
    --border-2: rgba(255, 255, 255, 0.16);

    --text: rgba(255, 255, 255, 0.92);
    --muted: rgba(255, 255, 255, 0.66);

    --primary: #b94b4b;
    --primary-2: #d05a5a;
    --danger: #c25555;

    --ok: #56b37a;
    --warn: #d4a64f;
    --info: #7aa7d9;

    --input-bg: rgba(255, 255, 255, 0.06);
    --input-border: rgba(255, 255, 255, 0.16);
    --input-border-hover: rgba(255, 255, 255, 0.24);

    --ring: 0 0 0 4px rgba(212, 166, 79, 0.26);

    --code-bg: rgba(212, 166, 79, 0.10);
    --code-border: rgba(212, 166, 79, 0.22);
  }
}

/* -----------------------------
   2) Base / Reset
------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--lh-normal);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 15% 10%, rgba(255,255,255,0.55), transparent 55%),
    radial-gradient(900px 700px at 85% 0%, rgba(255,255,255,0.35), transparent 60%),
    linear-gradient(180deg, var(--bg), rgba(239, 225, 196, 1));
}

/* paper grain overlay */
body::before {
  content:"";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .10;
  background:
    repeating-linear-gradient(0deg,
      rgba(0,0,0,.06) 0px,
      rgba(0,0,0,.06) 1px,
      transparent 2px,
      transparent 6px),
    repeating-linear-gradient(90deg,
      rgba(0,0,0,.03) 0px,
      rgba(0,0,0,.03) 1px,
      transparent 2px,
      transparent 7px);
  mix-blend-mode: multiply;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--info);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--s-6) 0;
}

/* -----------------------------
   3) App Layout Shell
------------------------------ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;

  /* Leather strip */
  background: linear-gradient(180deg, rgba(46,33,26,.92), rgba(34,25,20,.92));
  color: rgba(255,255,255,.92);

  border-bottom: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(12px);
}

@media (prefers-color-scheme: dark) {
  .app-header {
    background: linear-gradient(180deg, rgba(20,16,13,.92), rgba(14,11,9,.92));
    border-bottom: 1px solid rgba(255,255,255,.10);
  }
}

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.header-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  min-width: 170px;
}
.brand-title {
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: 0.02em;
}
.brand-subtitle {
  font-size: var(--text-sm);
  color: rgba(255,255,255,.70);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-left: auto;
}

.main {
  padding: var(--s-6) 0 var(--s-7);
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}

.page-title {
  margin: 0;
  font-size: var(--text-2xl);
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: var(--s-2) 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* -----------------------------
   4) Cards / Sections
------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(6px);
}

.card-inner {
  padding: var(--s-5);
}

.card + .card {
  margin-top: var(--s-5);
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  position: relative;
}

/* subtle deckle/edge texture */
.section-card::after {
  content:"";
  position:absolute;
  inset:-12px;
  pointer-events:none;
  opacity:.22;
  background:
    radial-gradient(12px 10px at 12px 12px, rgba(42,36,32,.08), transparent 60%),
    radial-gradient(10px 12px at calc(100% - 10px) 14px, rgba(42,36,32,.06), transparent 65%),
    radial-gradient(14px 10px at 18px calc(100% - 16px), rgba(42,36,32,.06), transparent 65%),
    radial-gradient(10px 14px at calc(100% - 16px) calc(100% - 18px), rgba(42,36,32,.08), transparent 65%);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);

  /* paper header gradient */
  background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,.28));
  border-bottom: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .section-head {
    background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  }
}

.section-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-body {
  padding: var(--s-5);
}

/* ink divider */
.hairline {
  height: 1px;
  width: 100%;
  background: linear-gradient(90deg, transparent, rgba(42,36,32,.25), transparent);
}

/* -----------------------------
   5) Buttons
------------------------------ */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.35);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: var(--text-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 2px 0 rgba(42,36,32,.14);
}

.btn:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(26,20,16,0.12);
}

.btn:active {
  transform: translateY(0px);
  box-shadow: 0 2px 0 rgba(42,36,32,.14);
}

.btn:focus {
  outline: none;
  box-shadow: var(--ring);
}

.btn-primary {
  border-color: rgba(0, 0, 0, 0.18);
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: rgba(255,255,255,.96);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #9a3131, #6b1f1f);
}

.btn-danger {
  border-color: rgba(0, 0, 0, 0.18);
  background: linear-gradient(180deg, #7a2020, #5a1717);
  color: rgba(255,255,255,.96);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: rgba(255,255,255,.92);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255,255,255,0.18);
}

.btn-sm {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
}

/* -----------------------------
   6) Forms
------------------------------ */
.form {
  display: grid;
  gap: var(--s-4);
}

.field {
  display: grid;
  gap: var(--s-2);
}

.label {
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.help {
  font-size: var(--text-xs);
  color: var(--muted);
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: var(--text-md);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.textarea {
  min-height: 140px;
  resize: vertical;
  line-height: var(--lh-normal);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--input-border-hover);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  box-shadow: var(--ring);
  border-color: rgba(179, 139, 61, 0.55);
}

.input[disabled],
.select[disabled],
.textarea[disabled] {
  opacity: 0.7;
  cursor: not-allowed;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
}
@media (max-width: 760px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.form-actions {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  justify-content: flex-end;
  padding-top: var(--s-2);
}

/* A notebook-ish "note block" style */
.note-block {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--r-md);
  padding: var(--s-4);
}
.note-block code,
.code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* -----------------------------
   7) Badges
------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  font-size: var(--text-xs);
  font-weight: 800;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.28);
}

@media (prefers-color-scheme: dark) {
  .badge {
    background: rgba(255, 255, 255, 0.06);
  }
}

.badge-draft { border-color: rgba(44, 74, 115, 0.40); }
.badge-played { border-color: rgba(45, 110, 65, 0.40); }
.badge-archived { border-color: rgba(160, 160, 160, 0.35); }

.badge-type {
  font-weight: 900;
  letter-spacing: 0.02em;
  background: rgba(179, 139, 61, 0.14);
  border-color: rgba(179, 139, 61, 0.34);
}

/* -----------------------------
   8) Lists / Tables
------------------------------ */
.list {
  display: grid;
  gap: var(--s-3);
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4);
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.list-item-title {
  font-weight: 900;
  letter-spacing: -0.01em;
}

.list-item-meta {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: var(--s-1);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.40);
}

.table th,
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.table th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,.25));
}

@media (prefers-color-scheme: dark) {
  .table {
    background: rgba(255,255,255,0.05);
  }
  .table th {
    background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.03));
  }
}

.table tr:last-child td {
  border-bottom: none;
}

/* -----------------------------
   9) Flash Messages
------------------------------ */
.flash {
  border-radius: var(--r-lg);
  padding: var(--s-4);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.55);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--s-4);
}

.flash-success {
  border-color: rgba(45, 110, 65, 0.35);
}

.flash-error {
  border-color: rgba(140, 40, 40, 0.35);
}

.flash-info {
  border-color: rgba(44, 74, 115, 0.35);
}

/* -----------------------------
   10) Attachments
------------------------------ */
.attachments {
  display: grid;
  gap: var(--s-3);
}

.attachment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4);
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.attachment-meta {
  display: grid;
  gap: var(--s-1);
}

.attachment-name {
  font-weight: 900;
  letter-spacing: -0.01em;
}

.attachment-desc {
  color: var(--muted);
  font-size: var(--text-sm);
}

.attachment-actions {
  display: flex;
  gap: var(--s-2);
  align-items: center;
}

/* Drop area (optional JS later) */
.dropzone {
  border: 1px dashed var(--border-2);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  background: rgba(255,255,255,0.35);
  text-align: center;
  color: var(--muted);
}

/* -----------------------------
   11) Search Results
------------------------------ */
.search-results {
  display: grid;
  gap: var(--s-3);
}

.search-result {
  padding: var(--s-5);
  background: rgba(255,255,255,0.50);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.search-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}

.search-result-title {
  font-size: var(--text-lg);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 0;
}

.search-result-snippet {
  margin: 0;
  color: var(--muted);
}

/* -----------------------------
   12) Utility Classes
------------------------------ */
.m-0 { margin: 0 !important; }
.mt-2 { margin-top: var(--s-2) !important; }
.mt-3 { margin-top: var(--s-3) !important; }
.mt-4 { margin-top: var(--s-4) !important; }
.mt-5 { margin-top: var(--s-5) !important; }
.mt-6 { margin-top: var(--s-6) !important; }

.mb-2 { margin-bottom: var(--s-2) !important; }
.mb-3 { margin-bottom: var(--s-3) !important; }
.mb-4 { margin-bottom: var(--s-4) !important; }
.mb-5 { margin-bottom: var(--s-5) !important; }

.flex { display: flex !important; }
.flex-col { display: flex !important; flex-direction: column !important; }
.items-center { align-items: center !important; }
.justify-between { justify-content: space-between !important; }
.gap-2 { gap: var(--s-2) !important; }
.gap-3 { gap: var(--s-3) !important; }
.gap-4 { gap: var(--s-4) !important; }

.muted { color: var(--muted) !important; }
.mono { font-family: var(--font-mono) !important; }
