/* Kaleidoscope Writing Community — main.css
   Design language: paper. Warm, textured, analogue. Technology disappears.
   The writer sees a page, not a product.
   Brand palette sourced from the Kaleidoscope Writers Community logo.
*/

/* ── Reset ───────────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] { display: none !important; }

/* ── Design Tokens ───────────────────────────────────────────────────────────── */

:root {
  /* Paper palette */
  --paper:          #f7f3ec;   /* warm off-white — aged notebook page */
  --paper-dark:     #ede8df;   /* slightly darker — header, dividers */

  /* Ink — sourced from the logo wordmark: cool dark navy */
  --ink:            #1e3050;   /* deep navy — primary text, logo wordmark */
  --ink-light:      #5a6e82;   /* faded navy — secondary text, meta, nav */
  --ink-faint:      #b8c4cf;   /* very faint — borders, empty states */

  /* Gold — sourced from the logo laurel sprigs */
  --accent:         #c4a030;   /* warm gold — links, primary actions */
  --accent-hover:   #a08020;   /* darker gold — hover state */

  /* Error */
  --error:          #8b2020;   /* deep red — errors */

  /* Spectrum palette (logo petal colours, outer → inner) */
  --spectrum-purple: #6b2d8a;
  --spectrum-indigo: #1e4da0;
  --spectrum-blue:   #1a7abf;
  --spectrum-green:  #2d8a3e;
  --spectrum-yellow: #e8c020;
  --spectrum-orange: #d4521a;
  --spectrum-red:    #b81a1a;

  /* Surfaces */
  --surface-page:       var(--paper);
  --surface-header:     var(--paper-dark);
  --surface-divider:    var(--paper-dark);

  /* Text */
  --text-primary:       var(--ink);
  --text-secondary:     var(--ink-light);
  --text-placeholder:   var(--ink-faint);
  --text-link:          var(--accent);
  --text-link-hover:    var(--accent-hover);
  --text-error:         var(--error);

  /* Borders */
  --border-default:     var(--ink-faint);
  --border-focus:       var(--ink-light);

  /* Interactive */
  --btn-bg:             var(--ink);
  --btn-bg-hover:       var(--accent);
  --btn-text:           var(--paper);

  /* Typography */
  --font-serif:   Georgia, 'Times New Roman', serif;
  --font-ui:      system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --font-size-base:   18px;
  --line-height-base: 1.7;

  --text-xs:  0.75rem;
  --text-sm:  0.85rem;
  --text-md:  1rem;
  --text-lg:  1.1rem;
  --text-xl:  1.6rem;

  --h1-size:        1.6rem;
  --h1-weight:      600;
  --h1-line-height: 1.25;
  --h1-tracking:    -0.01em;

  --h2-size:      0.75rem;
  --h2-weight:    600;
  --h2-transform: uppercase;
  --h2-tracking:  0.12em;

  --label-size:      0.8rem;
  --label-weight:    600;
  --label-transform: uppercase;
  --label-tracking:  0.08em;

  /* Spacing */
  --content-width:  640px;
  --auth-width:     400px;
  --page-padding:   24px;
  --header-height:  52px;

  --space-xs:   0.35rem;
  --space-sm:   0.65rem;
  --space-md:   1.25rem;
  --space-lg:   2.5rem;
  --space-xl:   3rem;
  --space-2xl:  5rem;

  /* Border & Radius */
  --radius-btn:  2px;
  --radius-code: 4px;

  /* Transitions */
  --transition-border: border-color 0.2s;
  --transition-bg:     background 0.15s;
  --transition-color:  color 0.3s;
}

@media (max-width: 480px) {
  :root { --font-size-base: 16px; }
}

/* ── Base ────────────────────────────────────────────────────────────────────── */

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--surface-page);
  background-image: linear-gradient(rgba(247, 243, 236, 0.50), rgba(247, 243, 236, 0.50)),
                    url('/images/background.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-serif);
  line-height: var(--line-height-base);
  min-height: 100dvh;
}

/* ── Typography ──────────────────────────────────────────────────────────────── */

h1 {
  font-size: var(--h1-size);
  font-weight: var(--h1-weight);
  line-height: var(--h1-line-height);
  letter-spacing: var(--h1-tracking);
}

h2 {
  font-size: var(--h2-size);
  font-weight: var(--h2-weight);
  text-transform: var(--h2-transform);
  letter-spacing: var(--h2-tracking);
  color: var(--text-secondary);
  font-family: var(--font-ui);
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

/* ── Layout — content pages ──────────────────────────────────────────────────── */

/* Pages with a header (pieces, dashboard) */
body:has(header) {
  display: flex;
  flex-direction: column;
}

/* Pages without header (login, register, recover) — centred single column */
body:not(:has(header)):not(.landing) {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px var(--page-padding) 80px;
}

body:not(:has(header)):not(.landing) > * {
  width: 100%;
  max-width: var(--auth-width);
}

body:not(:has(header)):not(.landing) > h1 {
  margin-bottom: 2rem;
}

/* ── Landing page ────────────────────────────────────────────────────────────── */

body.landing {
  min-height: 100dvh;
}

body.landing .centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 48px 24px 80px;
  text-align: center;
}

body.landing .logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 2rem;
}

body.landing h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

body.landing .tagline {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2rem;
}

body.landing .description {
  max-width: 420px;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-primary);
  margin-bottom: 2.5rem;
}

body.landing .actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

body.landing .note {
  margin-top: 0.75rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-placeholder);
}

body.landing .note:first-of-type {
  margin-top: 3rem;
}

body.landing .note a {
  color: var(--text-placeholder);
}

body.landing footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: none;
  border-top: 1px solid var(--border-default);
  background: var(--surface-header);
  padding: 10px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-placeholder);
}

body.landing footer a {
  color: var(--text-placeholder);
}

/* ── Header ──────────────────────────────────────────────────────────────────── */

header {
  background: var(--surface-header);
  border-bottom: 1px solid var(--border-default);
  padding: 0 var(--page-padding);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

header #member-name {
  color: var(--text-secondary);
  font-style: italic;
  font-family: var(--font-serif);
}

header nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

header nav a {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

header nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

/* ── Main content ────────────────────────────────────────────────────────────── */

main {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 48px var(--page-padding) 80px;
}

/* ── Forms ───────────────────────────────────────────────────────────────────── */

form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

form > div {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

label {
  font-family: var(--font-ui);
  font-size: var(--label-size);
  font-weight: var(--label-weight);
  text-transform: var(--label-transform);
  letter-spacing: var(--label-tracking);
  color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"] {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-default);
  padding: 0.4rem 0;
  outline: none;
  width: 100%;
  transition: var(--transition-border);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
  border-bottom-color: var(--border-focus);
}

input::placeholder {
  color: var(--text-placeholder);
}

.password-field {
  position: relative;
}

.password-field input[type="password"],
.password-field input[type="text"] {
  padding-right: 2rem;
}

.password-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-placeholder);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.password-toggle:hover {
  color: var(--text-secondary);
}

.password-toggle svg {
  pointer-events: none;
}

/* ── Checkbox row ────────────────────────────────────────────────────────────── */

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.checkbox-row label {
  font-size: var(--text-sm);
  color: var(--ink-light);
  cursor: pointer;
  margin: 0;
  font-weight: normal;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */

button[type="submit"],
a.btn,
#new-piece-btn {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: none;
  border-radius: var(--radius-btn);
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: var(--transition-bg);
  align-self: flex-start;
}

button[type="submit"]:hover,
a.btn:hover,
#new-piece-btn:hover {
  background: var(--btn-bg-hover);
  text-decoration: none;
  color: var(--btn-text);
}

/* Sign out button — ghost style */
#logout-btn {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

#logout-btn:hover {
  color: var(--text-primary);
}

/* ── Error / status messages ─────────────────────────────────────────────────── */

.error {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-error);
}

.hidden {
  display: none;
}

[aria-live] {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-height: 1.2em;
}

/* ── Pieces list ─────────────────────────────────────────────────────────────── */

#pieces-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

#new-piece-btn {
  font-size: var(--text-xs);
  padding: 0.4rem 1rem;
}

section + section {
  margin-top: var(--space-lg);
}

section h2 {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-default);
}

.pieces-list {
  list-style: none;
}

.pieces-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--surface-divider);
}

.pieces-list li.empty {
  color: var(--text-placeholder);
  font-style: italic;
  font-size: 0.95rem;
  justify-content: flex-start;
}

.pieces-list a {
  color: var(--text-primary);
  font-size: var(--text-md);
  flex: 1;
}

.pieces-list a:hover {
  color: var(--text-link);
  text-decoration: none;
}

.piece-meta {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-placeholder);
  white-space: nowrap;
}

.piece-author {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-style: italic;
  margin-right: 0.5rem;
}

/* ── Recovery code display ───────────────────────────────────────────────────── */

.recovery-code {
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  background: var(--surface-divider);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-code);
  padding: 0.75rem 1rem;
  text-align: center;
  user-select: all;
  word-break: break-all;
}

/* ── Welcome / info messages ─────────────────────────────────────────────────── */

#welcome-message {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-link);
  background: var(--surface-divider);
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: var(--auth-width);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  body:not(:has(header)) {
    padding-top: 48px;
  }

  main {
    padding-top: 32px;
  }

  header {
    padding: 0 16px;
  }
}
