:root {
  --color-background-dark: #2A0F14;
  --color-surface: #F6EBD2;
  --color-surface-muted: #E7D2A3;
  --color-primary: #6E1F2A;
  --color-secondary: #B88A3B;
  --color-highlight: #9E2F3A;
  --color-border: #4A2E1F;
  --color-text: #241914;
  --color-text-on-dark: #F8F1E3;
  --color-success: #3F6B45;
  --color-warning: #D49A32;
  --color-error: #8B1E2D;
  --parchment: var(--color-surface-muted);
  --parchment-light: var(--color-surface);
  --parchment-dark: var(--color-secondary);
  --ink: var(--color-text);
  --ink-soft: var(--color-secondary);
  --wood: var(--color-background-dark);
  --wood-light: var(--color-primary);
  --gold: var(--color-warning);
  --success: var(--color-success);
  --danger: var(--color-error);
  --shadow: 0 16px 45px color-mix(in srgb, var(--color-border) 24%, transparent);
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: var(--color-background-dark);
}

:root[data-theme="red"] {
  --color-background-dark: #2A0F14;
  --color-surface: #F6EBD2;
  --color-surface-muted: #E7D2A3;
  --color-primary: #6E1F2A;
  --color-secondary: #B88A3B;
  --color-highlight: #9E2F3A;
  --color-border: #4A2E1F;
  --color-text: #241914;
  --color-text-on-dark: #F8F1E3;
  --color-success: #3F6B45;
  --color-warning: #D49A32;
  --color-error: #8B1E2D;
}

:root[data-theme="green"] {
  --color-background-dark: #18251C;
  --color-surface: #F1E6CF;
  --color-surface-muted: #D9C8A6;
  --color-primary: #3D5F3C;
  --color-secondary: #7A4E2D;
  --color-highlight: #5D7B47;
  --color-border: #352519;
  --color-text: #211A13;
  --color-text-on-dark: #F4EAD8;
  --color-success: #4F7D45;
  --color-warning: #D1A348;
  --color-error: #8A3B2E;
}

:root[data-theme="blue"] {
  --color-background-dark: #0F1C28;
  --color-surface: #F3F6F5;
  --color-surface-muted: #D8E1E2;
  --color-primary: #2F5F87;
  --color-secondary: #5FA7A3;
  --color-highlight: #3D86A8;
  --color-border: #253341;
  --color-text: #15202A;
  --color-text-on-dark: #EAF0F2;
  --color-success: #4A7A57;
  --color-warning: #C79B45;
  --color-error: #A13A43;
}

:root[data-theme="stone"] {
  --color-background-dark: #1A1C1F;
  --color-surface: #F1EEE8;
  --color-surface-muted: #D5D0C6;
  --color-primary: #4E5E67;
  --color-secondary: #A88957;
  --color-highlight: #6F8A8F;
  --color-border: #33302B;
  --color-text: #1E1C19;
  --color-text-on-dark: #F2F1EC;
  --color-success: #56745B;
  --color-warning: #C99A42;
  --color-error: #9A4A42;
}

:root[data-theme="purple"] {
  --color-background-dark: #22132B;
  --color-surface: #F5EFF7;
  --color-surface-muted: #E3D2E6;
  --color-primary: #7B3F8E;
  --color-secondary: #D1A54A;
  --color-highlight: #B05AA8;
  --color-border: #3A2742;
  --color-text: #24192C;
  --color-text-on-dark: #F2EAF6;
  --color-success: #4D7559;
  --color-warning: #D4A241;
  --color-error: #A63C5C;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--color-primary) 48%, transparent), transparent 28rem),
    repeating-linear-gradient(95deg, color-mix(in srgb, var(--color-surface) 4%, transparent) 0 1px, transparent 1px 7px),
    var(--color-background-dark);
}

body.is-loading .app-shell { visibility: hidden; }

a { color: var(--color-primary); }
button, input, select, textarea { font: inherit; }

button, .button {
  border: 1px solid color-mix(in srgb, var(--color-border) 55%, transparent);
  border-radius: 8px;
  padding: .72rem 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}

button:hover, .button:hover { filter: brightness(1.04); transform: translateY(-1px); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--color-warning); outline-offset: 2px; }

.button-primary { color: var(--color-text-on-dark); background: linear-gradient(var(--color-primary), var(--color-background-dark)); box-shadow: 0 4px 12px color-mix(in srgb, var(--color-background-dark) 30%, transparent); }
.button-secondary { color: var(--ink); background: var(--parchment-light); }
.button-danger { color: var(--color-text-on-dark); background: var(--danger); }
.button-link { border: 0; padding: 0; color: var(--color-primary); background: transparent; text-decoration: underline; }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem clamp(1rem, 4vw, 3rem);
  color: var(--color-text-on-dark);
  background: linear-gradient(110deg, var(--color-background-dark), var(--color-primary) 65%, var(--color-secondary));
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 5px 18px color-mix(in srgb, var(--color-border) 34%, transparent);
}

.brand { --brand-text-size: clamp(1.05rem, 2.5vw, 1.4rem); display: flex; align-items: center; gap: .28rem; color: inherit; text-decoration: none; font-weight: 700; }
.brand-home { display: flex; align-items: center; gap: .28rem; color: inherit; text-decoration: none; }
.brand-logo { display: block; width: auto; height: calc(var(--brand-text-size) * 2.7); flex: none; object-fit: contain; }
.brand-name { font-size: var(--brand-text-size); white-space: nowrap; }
.app-context { color: var(--color-highlight); text-decoration: none; cursor: pointer; }

.account-nav { position: relative; }
.account-button { display: grid; width: 2.65rem; height: 2.65rem; place-items: center; padding: .35rem; color: var(--color-text-on-dark); background: color-mix(in srgb, var(--color-surface) 12%, transparent); border-color: color-mix(in srgb, var(--color-surface) 38%, transparent); }
.account-button span:not(.account-avatar) { display: none; }
.account-avatar { display: grid; width: 1.85rem; aspect-ratio: 1; place-items: center; border-radius: 50%; color: var(--ink); background: var(--gold); font: 700 .8rem Arial, sans-serif; }
.account-menu {
  position: absolute;
  top: calc(100% + .55rem);
  right: 0;
  display: grid;
  min-width: 12rem;
  padding: .45rem;
  border: 1px solid var(--parchment-dark);
  border-radius: 10px;
  background: var(--parchment-light);
  box-shadow: var(--shadow);
}
.account-menu[hidden] { display: none; }
.account-menu button { border: 0; text-align: left; background: transparent; }
.account-menu button:hover { background: color-mix(in srgb, var(--color-primary) 14%, transparent); }
.guest-actions { display: flex; align-items: center; gap: .65rem; }
.guest-actions[hidden], .account-nav[hidden] { display: none; }
.guest-actions .button { color: var(--color-text-on-dark); }
.guest-actions .button-secondary { color: var(--color-text); }

.page { width: min(1120px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 4rem) 0; color: var(--color-text-on-dark); }
.hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(250px, .6fr); gap: 2rem; align-items: center; margin-bottom: 2rem; }
.eyebrow { margin: 0 0 .5rem; color: var(--color-primary); font: 700 .78rem/1.2 Arial, sans-serif; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 17ch; margin-bottom: .7rem; font-size: clamp(2.2rem, 6vw, 4.8rem); line-height: .98; }
.lead { max-width: 55ch; color: var(--color-surface-muted); font-size: 1.12rem; line-height: 1.6; }
.hero-logo { display: block; width: min(15rem, 62vw); aspect-ratio: 1; place-self: center; object-fit: contain; filter: drop-shadow(0 14px 12px color-mix(in srgb, var(--color-border) 30%, transparent)); }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.2rem; }
.tool-card { display: flex; min-height: 18rem; flex-direction: column; padding: 1.4rem; color: var(--color-text); border: 1px solid var(--color-secondary); border-radius: 15px; background: color-mix(in srgb, var(--color-surface) 94%, transparent); box-shadow: 0 9px 24px color-mix(in srgb, var(--color-border) 16%, transparent); }
.tool-card.featured { border-top: 5px solid var(--color-highlight); }
.tool-card p { color: var(--ink-soft); line-height: 1.55; }
.tool-card .button { align-self: flex-start; margin-top: auto; }
.card-kicker { color: var(--color-primary); font: 700 .75rem Arial, sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.site-footer { display: flex; justify-content: center; gap: 1.3rem; padding: 1.5rem; color: var(--color-surface-muted); }
.site-footer a { color: var(--color-text-on-dark); }

.auth-screen { display: grid; min-height: 100vh; grid-template-rows: auto 1fr auto; }
.auth-header { padding: 1rem clamp(1rem, 4vw, 3rem); color: var(--color-text-on-dark); background: var(--wood); border-bottom: 3px solid var(--color-highlight); }
.auth-page { display: grid; width: min(100% - 2rem, 560px); margin: 2rem auto; align-items: center; }
.auth-card { padding: clamp(1.35rem, 4vw, 2.4rem); border: 1px solid var(--color-secondary); border-radius: 16px; background: color-mix(in srgb, var(--color-surface) 96%, transparent); box-shadow: var(--shadow); }
.auth-card h1 { font-size: 2.25rem; }
.auth-hint { color: var(--ink-soft); line-height: 1.5; }
.auth-switch { margin: 1.3rem 0 0; text-align: center; }

.form { display: grid; gap: .55rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form label { margin-top: .5rem; font-weight: 700; }
.form input {
  width: 100%;
  border: 1px solid var(--color-secondary);
  border-radius: 7px;
  padding: .75rem .8rem;
  color: var(--ink);
  background: var(--color-surface);
}
.privacy-consent { display: grid; grid-template-columns: auto 1fr; gap: .65rem; align-items: start; font-weight: 400 !important; line-height: 1.45; }
.privacy-consent input { width: auto; margin-top: .2rem; }
.form-message { min-height: 1.4em; margin: .4rem 0 0; color: var(--danger); }
.form-message.success { color: var(--success); }

dialog {
  width: min(660px, calc(100% - 1.5rem));
  max-height: min(88vh, 820px);
  overflow-y: auto;
  border: 1px solid var(--parchment-dark);
  border-radius: 15px;
  padding: 0;
  color: var(--ink);
  background: var(--parchment-light);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: color-mix(in srgb, var(--color-background-dark) 72%, transparent); backdrop-filter: blur(2px); }
.dialog-header { position: sticky; z-index: 2; top: 0; display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: 1rem 1.3rem; color: var(--color-text-on-dark); background: var(--wood); }
.dialog-header h2 { margin: 0; margin-right: auto; }
.dialog-actions { display: flex; gap: .45rem; align-items: center; margin-left: auto; }
.dialog-close,
.dialog-save { display: grid; width: 2.25rem; height: 2.25rem; place-items: center; padding: 0; color: var(--color-text-on-dark); background: transparent; border-color: color-mix(in srgb, var(--color-text-on-dark) 55%, transparent); }
.dialog-body { display: grid; gap: 1.3rem; padding: 1.4rem; }
.dialog-section { padding-bottom: 1.4rem; border-bottom: 1px solid var(--parchment-dark); }
.dialog-section:last-child { padding-bottom: 0; border: 0; }
.danger-zone { padding: 1rem; border: 1px solid var(--color-error); border-radius: 10px; background: color-mix(in srgb, var(--color-error) 9%, transparent); }

.legal-page { width: min(860px, calc(100% - 2rem)); margin: 2rem auto; padding: clamp(1.3rem, 4vw, 2.4rem); color: var(--color-text); border: 1px solid var(--parchment-dark); border-radius: 16px; background: var(--parchment-light); box-shadow: var(--shadow); line-height: 1.65; }
.legal-page h1 { font-size: clamp(2rem, 6vw, 3.6rem); }

.consent-dialog {
  z-index: 1000;
  width: min(600px, calc(100% - 1.5rem));
  color: var(--color-text);
  border: 2px solid var(--color-highlight);
  background: var(--color-surface);
}
.consent-dialog::backdrop { background: color-mix(in srgb, var(--color-background-dark) 82%, transparent); }
.consent-dialog-body { padding: clamp(1.25rem, 4vw, 2rem); }
.consent-dialog-body h2 { font-size: clamp(1.55rem, 4vw, 2.2rem); }
.consent-dialog-body p { line-height: 1.55; }
.consent-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem; }
.consent-denied {
  position: fixed;
  z-index: 999;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  max-width: min(520px, calc(100% - 2rem));
  gap: .8rem;
  align-items: center;
  padding: .8rem;
  color: var(--color-text);
  border: 1px solid var(--color-warning);
  border-radius: 12px;
  background: var(--color-surface);
  box-shadow: var(--shadow);
}

.feedback-header-button { margin-left: auto; }
.feedback-floating { position: fixed; z-index: 900; top: 1rem; right: 1rem; }
.feedback-dialog { width: min(760px, calc(100% - 1.5rem)); }
.feedback-list { display: grid; gap: .8rem; margin-top: 1rem; }
.feedback-card { padding: .9rem; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-surface-muted); }
.feedback-card summary { display: flex; justify-content: space-between; gap: 1rem; cursor: pointer; }
.feedback-card pre { overflow: auto; padding: .65rem; border-radius: 7px; background: color-mix(in srgb, var(--color-surface) 80%, transparent); font-size: .78rem; }
.feedback-card textarea, .feedback-card select, .feedback-dialog textarea { width: 100%; padding: .65rem; border: 1px solid var(--color-border); border-radius: 7px; background: var(--color-surface); }

@media (max-width: 680px) {
  .hero { grid-template-columns: 1fr; }
  .hero-logo { grid-row: 1; width: 8rem; }
  .form-grid { grid-template-columns: 1fr; gap: .2rem; }
  .brand-name { max-width: 11rem; }
  .account-label { display: none; }
  .tool-card { min-height: 15rem; }
  .consent-denied { left: 1rem; flex-direction: column; align-items: stretch; }
}
