@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --black: #0f0e0d;
  --white: #f5f2ed;
  --accent: #c8401a;
  --accent-light: #f0e8e2;
  --gray: #888580;
  --border: #d8d4ce;
  --card-bg: #ffffff;
  --bg: #f5f2ed;
  --hidden-color: #1a1816;
  --green: #1a7a4a;
  --font-display: 'Vazirmatn', sans-serif;
  --font-body: 'Vazirmatn', sans-serif;
  --radius: 4px;
  --radius-lg: 8px;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--black);
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Loading Screen ── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.4s ease;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; color: var(--white); }
.loading-logo {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}
.loading-bar {
  width: 200px;
  height: 2px;
  background: #333;
  margin: 0 auto;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.6s ease;
}

/* ── App Layout ── */
#app {
  display: none;
  min-height: 100vh;
}
#app.visible { display: block; }

/* ── Header ── */
.site-header {
  border-bottom: 1.5px solid var(--black);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-logo {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--black);
  letter-spacing: -0.02em;
}
.site-logo span { color: var(--accent); }
.header-meta {
  font-size: 11px;
  color: var(--gray);
  font-weight: 500;
  letter-spacing: 0.06em;
}

/* ── Game Layout ── */
.game-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 56px);
}

/* ── Sidebar ── */
.sidebar {
  border-left: 1.5px solid var(--black);
  background: var(--white);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.letter-panel {
  flex: 1;
  border-bottom: 1.5px solid var(--black);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  position: relative;
  background: var(--black);
  overflow: hidden;
}
.letter-panel-label {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #666;
  text-transform: uppercase;
}
.reroll-btn {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 11px;
  color: #666;
  background: none;
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
}
.reroll-btn:hover { color: var(--white); border-color: #666; }

.big-letter {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(80px, 16vw, 140px);
  font-weight: 700;
  color: var(--white);
  line-height: 1;
  user-select: none;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), opacity 0.15s;
  position: relative;
  z-index: 1;
}
.big-letter.spin {
  transform: scale(0.6) rotate(-10deg);
  opacity: 0;
}
.letter-category-tag {
  position: absolute;
  bottom: 14px;
  left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  color: #555;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.controls-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.time-box {
  border-left: 1px solid var(--border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}
.box-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--black);
  text-transform: uppercase;
}
.box-sub {
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
  width: fit-content;
}
.box-sub:hover { text-decoration: underline; }
.timer-display {
  font-family: var(--font-display); font-weight: 700;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--black);
  line-height: 1;
  margin-top: 4px;
  transition: color 0.3s;
}
.timer-display.running { color: var(--accent); }
.timer-display.warning { color: #e24b4a; }
.timer-display.done { color: #e24b4a; }

.play-box {
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: background 0.15s;
  background: var(--card-bg);
}
.play-box:hover { background: var(--accent-light); }
.play-box.state-running { background: var(--black); }
.play-box.state-running .box-label { color: var(--white); }
.play-box.state-done { background: var(--green); }
.play-box.state-done .box-label { color: var(--white); }
.play-icon {
  font-size: 2rem;
  margin-top: 4px;
  line-height: 1;
  color: var(--black);
  transition: color 0.15s;
}
.play-box.state-running .play-icon { color: var(--white); }
.play-box.state-done .play-icon { color: var(--white); }

/* Time preset dropdown */
.time-presets {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  background: var(--white);
  border: 1.5px solid var(--black);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: none;
  min-width: 130px;
  z-index: 50;
  box-shadow: 4px 4px 0 var(--black);
}
.time-presets.open { display: block; }
.preset-opt {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  font-family: var(--font-body);
  background: none;
  border: none;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  text-align: right;
  color: var(--black);
  font-weight: 500;
  transition: background 0.1s;
}
.preset-opt:last-child { border-bottom: none; }
.preset-opt:hover { background: var(--accent-light); }
.preset-opt.active { background: var(--black); color: var(--white); }

/* ── Main Content ── */
.main-content {
  display: flex;
  flex-direction: column;
}

.content-header {
  border-bottom: 1.5px solid var(--black);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
}
.content-title { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; }
.content-meta { font-size: 12px; color: var(--gray); }
.category-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent);
  letter-spacing: 0.04em;
}

/* ── Questions List ── */
.questions-list {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.question-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 0.5px solid var(--border);
  min-height: 52px;
  flex: 1;
  transition: background 0.15s;
}
.question-row:last-child { border-bottom: none; }
.question-row:hover { background: #faf9f7; }

.q-number {
  font-family: var(--font-display); font-weight: 700;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray);
  min-width: 22px;
  flex-shrink: 0;
}

.q-hidden-bar {
  height: 18px;
  background: var(--hidden-color);
  border-radius: 2px;
  opacity: 0.85;
  flex-shrink: 0;
  transition: width 0.3s ease;
}

.q-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--black);
  display: none;
  line-height: 1.4;
}
.q-text.visible { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── End Screen ── */
.end-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,14,13,0.85);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.end-overlay.visible { display: flex; }
.end-card {
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  text-align: center;
  box-shadow: 8px 8px 0 var(--black);
  max-width: 400px;
  width: 90%;
}
.end-icon { font-size: 3rem; margin-bottom: 12px; }
.end-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.end-sub { font-size: 14px; color: var(--gray); margin-bottom: 28px; line-height: 1.6; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn-primary {
  padding: 12px 24px;
  background: var(--black);
  color: var(--white);
  border: 2px solid var(--black);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-secondary {
  padding: 12px 24px;
  background: transparent;
  color: var(--black);
  border: 2px solid var(--black);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { background: var(--accent-light); }

/* ── Mobile ── */
@media (max-width: 640px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    border-left: none;
    border-bottom: 1.5px solid var(--black);
  }
  .letter-panel {
    flex: 0 0 100px;
    border-bottom: none;
    border-left: 1.5px solid var(--black);
    padding: 12px;
    min-height: 110px;
  }
  .big-letter { font-size: 58px; }
  .letter-panel-label { font-size: 9px; top: 8px; right: 8px; }
  .reroll-btn { top: 8px; left: 8px; font-size: 10px; padding: 3px 6px; }
  .letter-category-tag { font-size: 9px; bottom: 8px; }
  .controls-panel { flex: 1; display: grid; grid-template-columns: 1fr 1fr; }
  .time-box { padding: 12px 10px; }
  .timer-display { font-size: 1.8rem; }
  .play-box { padding: 12px 10px; }
  .play-icon { font-size: 1.6rem; }
  .main-content { grid-row: 2; }
  .question-row { padding: 0 14px; gap: 10px; min-height: 44px; }
  .q-text { font-size: 13px; }
  .content-header { padding: 10px 14px; }
  .site-header { padding: 0 14px; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
