/* =========================================
   Druid's Duel — Global Styles
   ========================================= */

:root {
  --ink:         #1c1008;
  --ink-soft:    #2e1f0c;
  --gold:        #c8a84b;
  --gold-light:  #e8c96a;
  --gold-dark:   #9a7a2a;
  --green-dark:  #1e3a1e;
  --green-mid:   #2d5a2d;
  --parchment:   #f2e6c8;
  --parchment-dark: #e4d4a8;
  --text-dark:   #1c1008;
  --text-mid:    #5a3e1e;
  --text-light:  #8a6840;
  --easy-color:  #4a7c4e;
  --med-color:   #8a6020;
  --hard-color:  #8a2020;
  --radius:      6px;
  --shadow:      0 2px 12px rgba(28,16,8,0.18);
  --shadow-lg:   0 6px 24px rgba(28,16,8,0.28);
}

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

html, body {
  height: 100%;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 18px;
  color: var(--text-dark);
  background: var(--parchment);
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Typography ─────────────────────────── */
h1, h2, h3, .nav-link, .btn-primary, .btn-secondary, .btn-ghost,
.difficulty-badge, .page-title, .auth-title, .lore-title, .section-title {
  font-family: 'Cinzel', serif;
}

/* ── Loading ─────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(28,16,8,0.6);
  display: flex; align-items: center; justify-content: center;
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(200,168,75,0.3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────── */
.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  z-index: 9000; background: var(--ink-soft); color: var(--gold);
  font-family: 'Cinzel', serif; font-size: 0.9rem;
  padding: 0.75rem 1.5rem; border-radius: var(--radius);
  border: 1px solid var(--gold-dark); box-shadow: var(--shadow-lg);
  pointer-events: none; white-space: nowrap;
}

/* ── Parchment card (NO burned edges) ────── */
.parchment {
  background: var(--parchment) url('../assets/parchment.png') center/cover;
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  border: none;
}

/* ── Buttons ─────────────────────────────── */
.btn-primary {
  display: inline-block; cursor: pointer;
  background: var(--green-dark); color: var(--gold);
  border: 2px solid var(--gold-dark); border-radius: var(--radius);
  padding: 0.65rem 1.5rem; font-size: 0.95rem; font-weight: 600;
  text-decoration: none; text-align: center;
  transition: background 0.2s, color 0.2s;
}
.btn-primary:hover { background: var(--green-mid); color: var(--gold-light); }

.btn-secondary {
  display: inline-block; cursor: pointer;
  background: var(--parchment); color: var(--ink);
  border: 2px solid var(--gold-dark); border-radius: var(--radius);
  padding: 0.65rem 1.5rem; font-size: 0.95rem; font-weight: 600;
  text-decoration: none; text-align: center;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--parchment-dark); }

.btn-ghost {
  display: inline-block; cursor: pointer;
  background: transparent; color: var(--text-mid);
  border: 1px solid var(--text-light); border-radius: var(--radius);
  padding: 0.6rem 1.4rem; font-size: 0.9rem;
  text-decoration: none; text-align: center;
  transition: border-color 0.2s, color 0.2s;
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

.btn-ghost-sm {
  background: transparent; color: var(--text-light); border: none;
  cursor: pointer; font-size: 0.85rem; padding: 0.2rem 0.5rem;
  border-radius: var(--radius);
}
.btn-ghost-sm:hover { color: var(--hard-color); }

.btn-stop {
  display: inline-block; cursor: pointer;
  background: var(--hard-color); color: #fff;
  border: 2px solid #6a1010; border-radius: var(--radius);
  padding: 0.75rem 2rem; font-size: 1.1rem; font-weight: 700;
  font-family: 'Cinzel', serif;
  transition: background 0.2s;
}
.btn-stop:hover { background: #a02828; }

.btn-full  { width: 100%; display: block; }
.btn-large { padding: 1rem 2rem; font-size: 1.1rem; }
.btn-sm    { padding: 0.3rem 0.8rem; font-size: 0.85rem; }

/* ── Nav ─────────────────────────────────── */
.main-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(28,16,8,0.95);
  border-bottom: 2px solid var(--gold-dark);
  backdrop-filter: blur(4px);
}
.nav-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.5rem 1.5rem;
}
.nav-brand { display: flex; align-items: center; }
.nav-logo  { height: 40px; width: auto; object-fit: contain; }
.nav-links {
  display: flex; align-items: center; gap: 0.25rem;
  flex-wrap: wrap; margin-left: auto;
}
.nav-link {
  color: var(--gold); text-decoration: none; font-size: 0.8rem;
  padding: 0.4rem 0.7rem; border-radius: var(--radius);
  transition: background 0.2s, color 0.2s;
  letter-spacing: 0.04em;
}
.nav-link:hover, .nav-link.active { background: var(--green-mid); color: var(--gold-light); }
.nav-logout { color: var(--text-light); }
.nav-logout:hover { color: var(--hard-color); background: transparent; }
.nav-hamburger {
  display: none; background: none; border: none; color: var(--gold);
  font-size: 1.4rem; cursor: pointer; margin-left: auto; padding: 0.25rem;
}

@media (max-width: 700px) {
  .nav-hamburger { display: block; }
  .nav-links {
    display: none; flex-direction: column; align-items: flex-start;
    position: absolute; top: 100%; left: 0; right: 0;
    background: rgba(28,16,8,0.98); padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--gold-dark);
  }
  .main-nav.mobile-open .nav-links { display: flex; }
}

/* ── Pages ───────────────────────────────── */
.page { min-height: 100vh; }

.page-content {
  max-width: 760px; margin: 0 auto;
  padding: 2rem 1.25rem;
}

.page-title {
  color: var(--gold); font-size: 1.8rem; text-align: center;
  margin-bottom: 1.5rem; letter-spacing: 0.06em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.section-title {
  font-size: 1.1rem; color: var(--ink); margin-bottom: 1rem;
  border-bottom: 1px solid var(--parchment-dark); padding-bottom: 0.5rem;
}

/* ── Cover / Landing ─────────────────────── */
.cover-page {
  min-height: 100vh;
  background: var(--parchment);
  display: flex; align-items: center; justify-content: center;
}
.cover-content {
  text-align: center; padding: 3rem 2rem;
  background: var(--parchment) url('../assets/parchment.png') center/cover;
  border-radius: 12px; border: none; max-width: 480px; width: 90%;
}
.cover-logo    { max-width: 280px; width: 80%; margin-bottom: 1rem; }
.cover-tagline { color: var(--text-mid); font-size: 1.1rem; margin-bottom: 2rem; letter-spacing: 0.1em; }
.cover-actions { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.cover-guest-links { color: var(--text-light); font-size: 0.95rem; }

.link-subtle { color: var(--gold-dark); text-decoration: none; font-family: 'Cinzel', serif; font-size: 0.85rem; }
.link-subtle:hover { color: var(--gold); }

/* ── Auth ────────────────────────────────── */
.auth-container {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
  background: var(--parchment);
}
.auth-card { width: 100%; max-width: 420px; }
.auth-title { font-size: 1.4rem; text-align: center; color: var(--ink); margin-bottom: 1.5rem; }

.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-mid); margin-bottom: 0.35rem; font-family: 'Cinzel', serif; letter-spacing: 0.04em; }
.form-group input, .form-select, .add-player-input-wrap input {
  width: 100%; padding: 0.6rem 0.8rem; font-size: 1rem;
  font-family: 'Crimson Text', serif; color: var(--ink);
  background: rgba(255,255,255,0.7); border: 1px solid var(--parchment-dark);
  border-radius: var(--radius); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-select:focus, .add-player-input-wrap input:focus {
  border-color: var(--gold); box-shadow: 0 0 0 2px rgba(200,168,75,0.25);
}

.form-error  { color: var(--hard-color); font-size: 0.9rem; margin-bottom: 0.75rem; padding: 0.5rem; background: rgba(138,32,32,0.1); border-radius: var(--radius); }
.form-success { color: var(--easy-color); font-size: 0.9rem; margin-bottom: 0.75rem; padding: 0.5rem; background: rgba(74,124,78,0.1); border-radius: var(--radius); }
.auth-links { display: flex; gap: 1rem; justify-content: center; margin-top: 1.25rem; align-items: center; font-size: 0.95rem; color: var(--text-light); }

/* ── Play Page ───────────────────────────── */
.play-step { }
.play-setup-card { margin-bottom: 1.25rem; }
.setup-hint { color: var(--text-mid); font-size: 0.95rem; margin-bottom: 1rem; }

/* Players list */
.players-list { margin-bottom: 1rem; }
.player-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.75rem; margin-bottom: 0.4rem;
  background: rgba(255,255,255,0.4); border-radius: var(--radius);
  border: 1px solid var(--parchment-dark);
}
.player-name  { font-size: 1rem; color: var(--ink); }
.linked-badge { color: var(--easy-color); font-size: 0.8rem; }
.add-player-row {
  display: flex; gap: 0.5rem; align-items: flex-start;
}
.add-player-input-wrap { position: relative; flex: 1; }
.add-player-input-wrap input { width: 100%; }

/* Friend suggestions dropdown */
.friend-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 200;
  background: var(--parchment); border: 1px solid var(--gold-dark);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 200px; overflow-y: auto;
}
.sug-item {
  padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.95rem;
  display: flex; gap: 0.5rem; align-items: center;
}
.sug-item:hover { background: var(--parchment-dark); }
.sug-handle { color: var(--text-light); font-size: 0.8rem; }

/* Filters */
.filter-panel { margin-bottom: 1.5rem; }
.filter-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(90,62,30,0.15);
}
.filter-row:last-child { border-bottom: none; }
.filter-label {
  font-family: 'Cinzel', serif; font-size: 0.8rem;
  color: var(--text-mid); min-width: 80px; letter-spacing: 0.04em;
}

/* Toggle checkboxes */
.toggle-group { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.toggle-btn { display: inline-flex; align-items: center; cursor: pointer; }
.toggle-btn input { display: none; }
.toggle-btn span {
  padding: 0.3rem 0.9rem; border-radius: 20px;
  font-family: 'Cinzel', serif; font-size: 0.8rem;
  border: 1px solid var(--parchment-dark); color: var(--text-mid);
  background: rgba(255,255,255,0.3); transition: all 0.15s;
}
.toggle-btn input:checked + span {
  background: var(--green-dark); color: var(--gold);
  border-color: var(--gold-dark);
}

/* Segmented control */
.segmented-control {
  display: inline-flex; border-radius: 20px;
  border: 1px solid var(--gold-dark); overflow: hidden;
  background: rgba(255,255,255,0.2);
}
.seg-btn {
  padding: 0.3rem 1rem; border: none; cursor: pointer;
  font-family: 'Cinzel', serif; font-size: 0.78rem;
  color: var(--text-mid); background: transparent;
  transition: all 0.15s; letter-spacing: 0.03em;
  border-right: 1px solid var(--parchment-dark);
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: var(--green-dark); color: var(--gold); }
.seg-btn:hover:not(.active) { background: rgba(200,168,75,0.15); }

/* Challenge card */
.challenge-card { margin-bottom: 1.25rem; }
.challenge-header {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem;
}
.challenge-id-label { font-size: 0.85rem; color: var(--text-light); font-family: 'Cinzel', serif; }
.difficulty-badge {
  display: inline-block; padding: 0.2rem 0.7rem; border-radius: 20px;
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; color: #fff;
}
.difficulty-badge.Easy   { background: var(--easy-color); }
.difficulty-badge.Medium { background: var(--med-color); }
.difficulty-badge.Hard   { background: var(--hard-color); }

.challenge-total { margin-top: 1rem; color: var(--text-mid); font-size: 1rem; }
.challenge-best  {
  margin-top: 0.5rem; font-size: 0.9rem; color: var(--gold-dark);
  font-family: 'Cinzel', serif; letter-spacing: 0.04em;
}

/* Weaves grid */
.weaves-grid {
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center;
  padding: 1rem 0;
}
.weave-item {
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  min-width: 72px;
}
.weave-item img { width: 120px; height: 120px; object-fit: contain; }
.weave-count { font-size: 1.4rem; font-weight: 700; color: var(--ink); font-family: 'Cinzel', serif; }
.weave-name  { font-size: 0.78rem; color: var(--text-mid); font-family: 'Cinzel', serif; letter-spacing: 0.04em; }

/* Timer */
.timer-block { text-align: center; margin: 1rem 0; }
.timer-display {
  font-family: 'Cinzel', serif; font-size: 3rem; font-weight: 700;
  color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  letter-spacing: 0.05em;
}
.timer-result {
  font-family: 'Cinzel', serif; font-size: 1.2rem; color: var(--gold-dark);
  margin-top: 0.4rem; letter-spacing: 0.04em;
}

/* Challenge actions */
.challenge-actions {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  justify-content: center; margin-top: 0.5rem;
}

.success-banner {
  text-align: center; padding: 1rem;
  background: rgba(74,124,78,0.15); border: 1px solid var(--easy-color);
  border-radius: var(--radius); color: var(--easy-color);
  font-family: 'Cinzel', serif; font-size: 1rem; margin-top: 1rem;
}

/* Finish card */
.finish-card { }
.optional { color: var(--text-light); font-size: 0.85rem; font-family: 'Crimson Text', serif; }
.photo-btns { display: flex; gap: 0.75rem; }
.photo-btns .photo-upload-label { flex: 1; min-width: 0; text-align: center; }
.photo-upload-label {
  display: block; padding: 0.75rem; text-align: center;
  border: 2px dashed var(--parchment-dark); border-radius: var(--radius);
  cursor: pointer; color: var(--text-mid); font-size: 0.95rem;
  transition: border-color 0.2s; overflow: hidden;
}
#photo-upload-text {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.photo-upload-label:hover { border-color: var(--gold); }
.photo-preview { margin-top: 0.75rem; }
.photo-preview img { max-width: 100%; max-height: 220px; border-radius: var(--radius); object-fit: cover; }

/* ── All Challenges ──────────────────────── */
.challenges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.challenge-tile {
  padding: 1rem; cursor: default;
  transition: transform 0.15s, box-shadow 0.15s;
}
.challenge-tile:hover { transform: translateY(-2px); }
.challenge-tile.completed { opacity: 0.85; }
.tile-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.tile-id     { font-size: 0.75rem; color: var(--text-light); font-family: 'Cinzel', serif; margin-left: auto; }
.done-badge  { color: var(--easy-color); font-size: 0.9rem; }
.tile-weaves { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.tile-weave  { display: flex; align-items: center; gap: 0.2rem; font-size: 0.85rem; color: var(--text-mid); }
.tile-weave img { width: 20px; height: 20px; object-fit: contain; }
.tile-footer { display: flex; justify-content: space-between; align-items: center; }
.tile-total  { font-size: 0.85rem; color: var(--text-mid); }
.tile-best   { font-size: 0.8rem; color: var(--gold-dark); font-family: 'Cinzel', serif; }
.empty-state { text-align: center; color: var(--text-light); padding: 2.5rem; font-size: 1rem; }

/* ── History ─────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 1rem; }
.history-item { }
.history-header {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.history-date   { font-size: 0.85rem; color: var(--text-light); margin-left: auto; }
.history-weaves { font-size: 0.9rem; color: var(--text-mid); margin-bottom: 0.4rem; }
.history-players { font-size: 0.9rem; color: var(--text-mid); margin-bottom: 0.5rem; }
.history-player  { }
.history-player.winner { color: var(--gold-dark); font-weight: 600; }
.history-photo img { max-width: 100%; max-height: 260px; border-radius: var(--radius); object-fit: cover; margin-top: 0.5rem; }

/* ── Friends / Circle ────────────────────── */
.friends-section { margin-bottom: 1.25rem; }
.search-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search-row input { flex: 1; }
.friends-list { display: flex; flex-direction: column; gap: 0.5rem; }
.friend-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.35); border-radius: var(--radius);
  border: 1px solid var(--parchment-dark);
}
.friend-name   { font-size: 1rem; color: var(--ink); }
.friend-handle { font-size: 0.82rem; color: var(--text-light); margin-left: auto; }

/* ── Profile ─────────────────────────────── */
.profile-card { }
.stats-row {
  display: flex; gap: 1rem; justify-content: center;
  margin-bottom: 2rem; flex-wrap: wrap;
}
.stat-box {
  display: flex; flex-direction: column; align-items: center;
  min-width: 90px; padding: 1rem;
  background: rgba(255,255,255,0.3); border-radius: var(--radius);
  border: 1px solid var(--parchment-dark);
}
.stat-number { font-family: 'Cinzel', serif; font-size: 2rem; color: var(--ink); }
.stat-label  { font-family: 'Cinzel', serif; font-size: 0.72rem; color: var(--text-mid); letter-spacing: 0.05em; }

/* ── Rules / Lore pages ──────────────────── */
.lore-page {
  max-width: 760px; margin: 0 auto; padding: 0 2rem 3rem;
}

/* header/footer images sit INSIDE parchment, inset from edges */
.lore-content {
  padding: 0 2.5rem;     /* left/right keeps braids inside visible parchment */
  overflow: hidden;
}
.lore-knot-img {
  display: block; width: 100%; height: auto;
}
.lore-knot-img:first-child { margin-top: 3.5rem; }    /* doubled: braid breathes at top */
.lore-knot-img:last-child  { margin-bottom: 3.5rem; }  /* doubled: braid breathes at bottom */
.lore-body {
  padding: 0.75rem 0.5rem 3rem; /* tight top → title hugs header braid */
}
.lore-title {
  font-size: 1.8rem; color: var(--ink); text-align: center;
  margin-bottom: 2rem; letter-spacing: 0.06em;
}
.lore-content h2 {
  font-size: 1.15rem; color: var(--ink-soft);
  margin: 1.8rem 0 0.6rem; letter-spacing: 0.04em;
}
.lore-content p {
  line-height: 1.75; color: var(--text-dark);
  margin-bottom: 0.8rem; font-size: 1.05rem;
}
.lore-content strong { color: var(--ink-soft); }

/* ── Admin ───────────────────────────────── */
.admin-wrap { overflow-x: auto; }
.admin-table {
  width: 100%; border-collapse: collapse;
  background: var(--parchment); border-radius: var(--radius);
  overflow: hidden; font-size: 0.9rem;
}
.admin-table th {
  background: var(--green-dark); color: var(--gold);
  padding: 0.6rem 0.75rem; font-family: 'Cinzel', serif;
  font-size: 0.75rem; letter-spacing: 0.04em; text-align: left;
}
.admin-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--parchment-dark); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(200,168,75,0.08); }

/* ── Responsive ──────────────────────────── */
@media (max-width: 520px) {
  .timer-display    { font-size: 2.2rem; }
  .challenge-actions { flex-direction: column; align-items: stretch; }
  .challenges-grid  { grid-template-columns: 1fr 1fr; }
  .lore-body        { padding: 1rem 0.5rem 2rem; }
  .stats-row        { gap: 0.5rem; }
  .page-content     { padding: 1.25rem 1rem; }
}
