:root {
  --bg: #f4f8f6;
  --bg-card: #ffffff;
  --text: #223028;
  --text-muted: #5f7267;
  --accent: #2c6e4f;
  --accent-dark: #1f4f39;
  --border: #d9e6df;
  --danger: #b3392c;
  --red-suit: #b3392c;
  --black-suit: #223028;
}

* { box-sizing: border-box; }

/* Guards against any component rule accidentally winning over the hidden attribute on
   same-specificity grounds — JS toggles [hidden] to reveal exercise feedback. */
[hidden] { display: none !important; }

html { font-size: 18px; } /* larger base size — many learners are older */

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a { color: var(--accent-dark); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-dark);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.site-nav { display: flex; align-items: center; }
.site-nav a { margin-left: 1.5rem; text-decoration: none; color: var(--text); font-weight: 500; }
.site-nav a:hover { color: var(--accent); }
.nav-logout { margin-left: 1.5rem; font-size: 1rem; }

.site-main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem;
}

@media (max-width: 600px) {
  .site-header { padding: 0.75rem 1rem; }
  .brand { font-size: 1.3rem; }
  .site-nav a, .nav-logout { margin-left: 1rem; font-size: 0.95rem; }
  .site-main { padding: 1.25rem 1rem; }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; }
.page-sub { color: var(--text-muted); margin: 0; }

.empty-state { color: var(--text-muted); }

/* ---- Learner: recent updates panel ---- */

.updates-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.updates-panel h2 { margin: 0 0 0.6rem; font-size: 1.1rem; }
.updates-list { margin: 0; padding-left: 1.2rem; }
.updates-list li { margin-bottom: 0.4rem; }
.update-date { color: var(--text-muted); font-size: 0.9rem; margin-right: 0.4rem; }

/* ---- Learner: chapter list ---- */

.chapter-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }

.chapter-card a {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.4rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1.15rem;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.chapter-card a:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(30, 60, 45, 0.1);
}

/* ---- Chapter detail ---- */

.back-link { display: inline-block; margin-bottom: 1rem; text-decoration: none; }

.chapter-content { font-size: 1.05rem; }
.chapter-content h2 { color: var(--accent-dark); }
.chapter-content h3 { color: var(--accent-dark); font-size: 1.1rem; }
.chapter-content ul, .chapter-content ol { padding-left: 1.3rem; }

.content-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.content-table th, .content-table td {
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.content-table th { background: var(--bg); font-weight: 600; }
.content-table tbody tr:last-child td { border-bottom: none; }
.table-note { color: var(--text-muted); font-size: 0.9rem; }

/* Every chapter-content table is wrapped in this — scrolls horizontally instead of
   squeezing illegibly or overflowing the page, same pattern as the admin tables.
   Unconditional (not just a mobile media query): harmless on desktop since a table that
   already fits shows no scrollbar, but it's the safety net for any table at any width. */
.content-table-wrap { overflow-x: auto; }

.chapter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 2rem;
}

.button-link {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.7rem 1.3rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1rem;
  display: inline-block;
}
.button-link-secondary { background: var(--accent-dark); }

.link-button {
  background: none;
  border: none;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  text-decoration: underline;
}
.link-button.danger { color: var(--danger); }

.inline-form { display: inline; }

/* ---- Exercises: quiz ---- */

.quiz-question {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1rem;
}
.quiz-question-text { font-weight: 600; margin: 0 0 0.75rem; }
.quiz-done-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.55rem;
  margin-left: 0.5rem;
}
.quiz-option-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 48px;
}
.quiz-option-btn.correct { background: #dcf0e3; border-color: var(--accent); }
.quiz-option-btn.incorrect { background: #f7dedb; border-color: var(--danger); }
.quiz-feedback { margin-top: 0.5rem; color: var(--text-muted); }

/* ---- Exercises: bidding box ---- */

.bidding-scenario {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.5rem;
}
.hand-notation {
  font-family: "Courier New", monospace;
  letter-spacing: 0.02em;
  font-size: 1.1rem;
  display: inline-block;
  margin: 0.4rem 0;
}
.auction-history { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.auction-call {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-family: "Courier New", monospace;
}
.bidding-prompt { font-weight: 600; margin: 0.6rem 0; }

.bidding-box {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin: 0.75rem 0;
}
.bidding-box-specials {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.bid-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.3rem;
  font-family: "Courier New", monospace;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}
/* Suit-color classes are generic — used on bid-box buttons AND on individual suit-symbol
   characters wrapped in spans anywhere else in the app (chapter text, quiz, hand notation). */
.suit-red { color: var(--red-suit); }
.suit-black { color: var(--black-suit); }
.bid-btn:hover { background: var(--border); }
.bid-btn.correct { background: #dcf0e3; border-color: var(--accent); }
.bid-btn.incorrect { background: #f7dedb; border-color: var(--danger); }

.bidding-feedback { margin: 0.6rem 0; font-weight: 600; }
.bidding-controls { display: flex; gap: 0.75rem; margin-top: 0.75rem; flex-wrap: wrap; }
.bidding-controls button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.bidding-controls .secondary-btn { background: var(--text-muted); }

/* ---- Exercises: planning (fill-in trump/tricks, then check) ---- */

.planning-exercise {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.5rem;
}
.planning-hands {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 0.75rem 0;
}
@media (max-width: 600px) {
  .planning-hands { grid-template-columns: 1fr; }
}
.planning-hand-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}
.planning-hand-label { font-weight: 600; margin: 0 0 0.3rem; font-size: 0.9rem; color: var(--text-muted); }
.planning-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin: 0.75rem 0;
}
.planning-field-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.planning-field-label select,
.planning-field-label input {
  font-weight: normal;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  min-height: 44px;
}
.planning-controls button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.planning-feedback { margin-top: 0.75rem; }
.planning-result-ok { color: var(--accent-dark); font-weight: 600; }
.planning-result-bad { color: var(--danger); font-weight: 600; }
.planning-contract-line { font-weight: 600; }

.planning-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-card);
}

/* Bidding box always keeps 5 columns (♣♦♥♠NT) so a level's row never splits across lines —
   a real bidding box always shows all 5 denominations of a level together. Only the padding/
   font-size/gap shrink on narrow screens to keep 5 columns fitting without horizontal scroll. */
@media (max-width: 480px) {
  .bidding-box { gap: 0.25rem; }
  .bid-btn { font-size: 0.8rem; padding: 0.45rem 0.1rem; min-height: 40px; }
}
@media (max-width: 360px) {
  .site-main { padding: 1rem 0.6rem; }
  .bidding-scenario { padding: 0.9rem 0.7rem; }
  .bidding-box { gap: 0.2rem; }
  .bid-btn { font-size: 0.72rem; padding: 0.4rem 0.05rem; }
}

/* ---- Admin ---- */

.admin-header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }

.table-scroll { overflow-x: auto; border-radius: 12px; }

.admin-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}
.admin-row-actions { display: flex; gap: 0.75rem; }

.position-table input.position-input { width: 5rem; padding: 0.4rem; }

.admin-login-wrap { max-width: 360px; margin: 3rem auto; text-align: center; }
.admin-login-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.admin-login-form input, .admin-login-form label {
  text-align: left;
}
.admin-login-form input {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.admin-login-form label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.95rem; }
.admin-login-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
}

.form-error { color: var(--danger); font-weight: 600; }
.filter-hint { color: var(--text-muted); font-size: 0.9rem; }

.bridge-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 720px;
}
.bridge-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.bridge-form input,
.bridge-form textarea,
.bridge-form select {
  font-weight: normal;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
}
.narrow-field { max-width: 200px; }
.form-section-label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; }

.current-photo { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }
.remove-photo-label { font-weight: normal; font-size: 0.85rem; display: flex; align-items: center; gap: 0.35rem; }

.quiz-row, .scenario-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-card);
}
.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
@media (max-width: 600px) {
  .quiz-options { grid-template-columns: 1fr; }
}
.quiz-option-field { font-size: 0.85rem; }
.scenario-steps-textarea { font-family: "Courier New", monospace; font-size: 0.9rem; }

.remove-row-btn {
  align-self: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--danger);
  width: 44px;
  min-height: 40px;
}

.todo-add-form { max-width: 520px; margin-bottom: 1.5rem; }
.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
}
.todo-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  min-height: 0;
  cursor: pointer;
  font-size: 1rem;
  color: var(--accent);
  flex-shrink: 0;
}
.todo-item.todo-done .todo-text { text-decoration: line-through; color: var(--text-muted); }
.todo-text { flex: 1; }

.form-actions { margin-top: 0.5rem; }
.form-actions button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
  min-height: 48px;
}
