/* ── Skeuomorphic Hyper-Realistic Theme for catur.org/openings ── */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700;800&family=Outfit:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  --wood-dark: #1e120b;
  --wood-mid: #2d1c13;
  --wood-frame: #40281b;
  --gold-primary: #d4af37;
  --gold-light: #f9e79f;
  --gold-shadow: #8a6d1b;
  --leather-bg: #14110f;
  --panel-bg: rgba(28, 22, 18, 0.85);
  --panel-border: rgba(184, 148, 80, 0.3);
  --text-main: #f0e6d2;
  --text-muted: #a69984;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--leather-bg);
  background-image: 
    radial-gradient(circle at 50% 20%, rgba(212, 175, 55, 0.08) 0%, transparent 60%),
    radial-gradient(circle at 50% 80%, rgba(0, 0, 0, 0.8) 0%, transparent 70%),
    repeating-linear-gradient(45deg, rgba(0,0,0,0.15) 0px, rgba(0,0,0,0.15) 2px, transparent 2px, transparent 4px),
    linear-gradient(180deg, #181310 0%, #0d0a08 100%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ── Skeuomorphic Mahogany Header Bar with Brass Rim ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.8rem;
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.4) 100%),
    linear-gradient(90deg, #3d2314 0%, #52311c 50%, #3d2314 100%);
  border-bottom: 3px solid #d4af37;
  box-shadow: 
    inset 0 1px 1px rgba(255,255,255,0.3),
    inset 0 -2px 5px rgba(0,0,0,0.6),
    0 6px 20px rgba(0,0,0,0.7);
  position: relative;
  z-index: 10;
}

.topbar h1 {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff3d1 0%, #d4af37 60%, #997a20 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.9));
}

.topbar nav {
  display: flex;
  gap: 0.5rem;
  background: rgba(0,0,0,0.35);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.2);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
}

.nav-btn {
  background: linear-gradient(180deg, #3a2e26 0%, #241b16 100%);
  color: #b8aa95;
  border: 1px solid rgba(0,0,0,0.8);
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.1),
    0 2px 4px rgba(0,0,0,0.4);
  transition: all 0.2s ease;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

.nav-btn:hover {
  color: #fff;
  background: linear-gradient(180deg, #4d3d33 0%, #33261f 100%);
}

.nav-btn.active {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 60%),
    linear-gradient(180deg, #c59b27 0%, #8a6814 100%);
  color: #fff;
  border: 1px solid #ffe89e;
  box-shadow: 
    inset 0 1px 1px rgba(255,255,255,0.5),
    0 3px 8px rgba(0,0,0,0.6),
    0 0 12px rgba(212, 175, 55, 0.4);
}

/* ── Main Container View ── */
.view {
  display: none;
  padding: 1.5rem 1rem;
  max-width: 1040px;
  margin: 0 auto;
}
.view.active { display: block; }

/* ── Skeuomorphic Card / Panel ── */
.panel {
  background: 
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.03) 0%, transparent 70%),
    linear-gradient(180deg, rgba(38,29,23,0.92) 0%, rgba(22,17,13,0.95) 100%);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.5rem;
  box-shadow: 
    inset 0 1px 1px rgba(255, 235, 190, 0.1),
    0 10px 30px rgba(0,0,0,0.7),
    0 0 15px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}

.panel h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.35rem;
  color: var(--gold-light);
  margin-top: 0;
  margin-bottom: 0.8rem;
  letter-spacing: 0.5px;
}

.rep-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── Skeuomorphic Brass & Wood Buttons ── */
.btn {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.3) 100%),
    linear-gradient(180deg, #4a3c31 0%, #2a2018 100%);
  color: var(--text-main);
  border: 1px solid #5a493b;
  border-radius: 7px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.25),
    0 3px 6px rgba(0,0,0,0.5);
  transition: all 0.15s ease;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

.btn:hover {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.3) 0%, transparent 50%),
    linear-gradient(180deg, #5c4b3d 0%, #362920 100%);
  border-color: #7a6452;
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.35),
    0 4px 10px rgba(0,0,0,0.6);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.7);
}

.btn.primary {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.4) 100%),
    linear-gradient(180deg, #d4af37 0%, #8a6d1b 100%);
  color: #120b04;
  border: 1px solid #ffe89e;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
  box-shadow: 
    inset 0 1px 1px rgba(255,255,255,0.6),
    0 4px 12px rgba(0,0,0,0.5),
    0 0 10px rgba(212, 175, 55, 0.3);
}

.btn.primary:hover {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.35) 0%, transparent 50%),
    linear-gradient(180deg, #e5bf45 0%, #9e7d22 100%);
  box-shadow: 
    inset 0 1px 1px rgba(255,255,255,0.7),
    0 6px 16px rgba(0,0,0,0.6),
    0 0 15px rgba(212, 175, 55, 0.5);
}

.btn.small { padding: 0.35rem 0.8rem; font-size: 0.85rem; }

.btn.danger {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 50%),
    linear-gradient(180deg, #a03a32 0%, #68201a 100%);
  border-color: #c9564c;
  color: #fff;
}

.btn.danger:hover {
  background: 
    linear-gradient(180deg, rgba(255,255,255,0.3) 0%, transparent 50%),
    linear-gradient(180deg, #b8433a 0%, #7d2720 100%);
}

.btn:disabled { opacity: 0.4; cursor: default; transform: none; box-shadow: none; }
.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.muted { color: var(--text-muted); }
.small-text { font-size: 0.82rem; display: block; margin-bottom: 0.3rem; }

/* ── Study Home Section ── */
.due-hero {
  font-size: 1.5rem;
  font-family: 'Cinzel', serif;
  margin-bottom: 0.8rem;
  color: var(--text-main);
}
.due-hero span {
  font-weight: 700;
  color: var(--gold-primary);
  text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

.mode-pick {
  display: flex;
  gap: 1.6rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}
.mode-pick label {
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.mode-pick input[type=radio] {
  accent-color: var(--gold-primary);
}

.due-list {
  list-style: none;
  margin: 1.2rem 0 0;
  padding: 0;
}
.due-list li {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  margin-bottom: 4px;
}
.due-list .line-name { flex: 1; font-weight: 500; }
.due-list em { color: var(--text-muted); font-style: normal; font-size: 0.85rem; }
.due-n {
  font-variant-numeric: tabular-nums;
  color: var(--gold-primary);
  font-weight: 700;
}

.tag-w, .tag-b, .tag-custom {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.2), 0 1px 3px rgba(0,0,0,0.5);
}
.tag-w { background: #e6dfd1; color: #261c14; border: 1px solid #fff; }
.tag-b { background: #261c14; color: #e6dfd1; border: 1px solid #4d3b2c; }
.tag-custom { background: rgba(212, 175, 55, 0.15); color: var(--gold-light); border: 1px solid var(--gold-primary); }

/* ── Drill Layout & Boards ── */
.drill-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--gold-light);
  font-family: 'Cinzel', serif;
}
.drill-body { display: flex; gap: 1.4rem; flex-wrap: wrap; }

/* ── Skeuomorphic Handcrafted Wooden Board Frame ── */
.board-wrap {
  width: min(480px, 100%);
  flex-shrink: 0;
  padding: 14px;
  background: 
    linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 40%, rgba(0,0,0,0.4) 100%),
    radial-gradient(circle at 50% 50%, #4a2e1b 0%, #2b180d 100%);
  border: 2px solid #6e482b;
  border-radius: 8px;
  box-shadow: 
    inset 0 2px 4px rgba(255,255,255,0.3),
    inset 0 -3px 6px rgba(0,0,0,0.8),
    0 12px 35px rgba(0,0,0,0.8),
    0 0 20px rgba(0,0,0,0.5);
  position: relative;
}

#studyBoard, #builderBoard {
  width: 100% !important;
  border: 2px solid #1a0f08;
  border-radius: 4px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.7);
  overflow: hidden;
}

.side-panel {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Click-to-move square highlight ── */
[data-square].sq-sel::after {
  content: ;
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px rgba(212, 175, 55, 0.9);
  background: rgba(212, 175, 55, 0.2);
}
[data-square] { position: relative; }

.flash-ok #studyBoard { box-shadow: 0 0 0 5px #4ade80, 0 0 20px rgba(74, 222, 128, 0.5); }
.flash-bad #studyBoard { box-shadow: 0 0 0 5px #f87171, 0 0 20px rgba(248, 113, 113, 0.5); }

.feedback {
  padding: 0.9rem 1.1rem;
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  min-height: 3.5rem;
  font-size: 1rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
  line-height: 1.4;
}
.feedback.ok {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.4);
  color: #86efac;
}
.feedback.bad {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

.grade-row { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.grade-row button {
  flex: 1;
  padding: 0.6rem 0;
  border: 1px solid #4a3b2c;
  background: linear-gradient(180deg, #36291e 0%, #201710 100%);
  color: var(--text-main);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15), 0 2px 4px rgba(0,0,0,0.4);
  transition: all 0.15s ease;
}
.grade-row button:hover {
  background: linear-gradient(180deg, #473729 0%, #2c2017 100%);
  border-color: var(--gold-primary);
  color: #fff;
}
.grade-row button.pre {
  background: linear-gradient(180deg, #d4af37 0%, #8a6d1b 100%);
  color: #120b04;
  border-color: #ffe89e;
  font-weight: 700;
}

.big-ok { font-size: 1.35rem; font-weight: 700; color: #86efac; margin-top: 0; }

/* ── Repertoire List ── */
.line-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
  margin-bottom: 6px;
}
.line-info { flex: 1; min-width: 0; }
.line-title { font-weight: 600; font-size: 1rem; color: var(--gold-light); }
.line-title em { color: var(--text-muted); font-style: normal; font-size: 0.85rem; }
.line-meta { font-size: 0.83rem; color: var(--text-muted); margin: 0.2rem 0 0.4rem; }

.mastery-bar {
  height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 3px;
  max-width: 260px;
  border: 1px solid rgba(255,255,255,0.05);
  overflow: hidden;
}
.mastery-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8a6d1b 0%, #d4af37 100%);
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.5);
}
.line-actions { display: flex; flex-direction: column; gap: 0.4rem; }
.toggle input { width: 1.2rem; height: 1.2rem; cursor: pointer; accent-color: var(--gold-primary); }

/* ── Builder Controls ── */
.builder-controls { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 0.8rem; }
.builder-controls label { display: flex; align-items: center; gap: 0.8rem; font-size: 0.92rem; font-weight: 500; }
.builder-controls input[type=text], .builder-controls select {
  padding: 0.45rem 0.7rem;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
}
.builder-controls input[type=text]:focus, .builder-controls select:focus {
  border-color: var(--gold-primary);
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.3);
}

.moves-list {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  background: rgba(0,0,0,0.3);
  padding: 0.7rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.05);
  min-height: 2.5rem;
}

/* ── Stats Section ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.4rem;
}
.stat {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 1rem 0.8rem;
  text-align: center;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}
.stat b {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  display: block;
  color: var(--gold-primary);
  text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}
.stat span { font-size: 0.82rem; color: var(--text-muted); }

.hist-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.hist-table th, .hist-table td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.hist-table th { color: var(--gold-light); font-family: 'Cinzel', serif; font-size: 0.85rem; }
.hist-table .g-0 { color: #f87171; font-weight: 600; }
.hist-table .g-1 { color: #fbbf24; }
.hist-table .g-2 { color: #4ade80; }
.hist-table .g-3 { color: #34d399; font-weight: 700; }

.file-label { position: relative; overflow: hidden; display: inline-block; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── Skeuomorphic Pawn Promotion Dialog ── */
#promoDialog {
  display: none;
  position: fixed;
  z-index: 50;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #3d2a1e 0%, #1e140d 100%);
  border: 2px solid var(--gold-primary);
  border-radius: 12px;
  padding: 0.9rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.9), 0 0 25px rgba(212, 175, 55, 0.4);
}
#promoDialog.show { display: flex; gap: 0.7rem; }
.promo-btn {
  background: linear-gradient(180deg, #4d3829 0%, #2b1d14 100%);
  border: 1px solid #6e523b;
  border-radius: 8px;
  padding: 0.4rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.promo-btn img { width: 56px; height: 56px; display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8)); }
.promo-btn:hover {
  background: linear-gradient(180deg, #6e523b 0%, #4a3424 100%);
  border-color: var(--gold-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

@media (max-width: 700px) {
  .drill-body { flex-direction: column; }
  .board-wrap { width: 100%; padding: 8px; }
  .line-row { flex-wrap: wrap; }
  .line-actions { flex-direction: row; }
}

.js-error {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 99;
  background: #a03a32;
  color: #fff;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}
