/* ── Local fonts ─────────────────────────────── */
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/playfair-display-v40-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/playfair-display-v40-latin-700.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url("fonts/source-sans-3-v19-latin-300.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/source-sans-3-v19-latin-regular.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/source-sans-3-v19-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/source-sans-3-v19-latin-700.woff2") format("woff2");
}

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

body {
  font-family: "Source Sans 3", sans-serif;
  min-height: 100vh;
  background: #c8b49a;
  background-image:
    radial-gradient(ellipse at 20% 10%, #d4c4ad 0%, transparent 60%),
    radial-gradient(ellipse at 80% 90%, #b89e84 0%, transparent 60%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 3rem 1.5rem 4rem;
}

/* ── Paper ─────────────────────────────────── */
.paper {
  background: #fefcf5;
  width: 100%;
  max-width: 900px;
  border-radius: 3px;
  padding: 3rem 3.5rem 3.5rem;
  box-shadow:
    0 2px 4px rgba(80, 50, 20, 0.1),
    0 6px 12px rgba(80, 50, 20, 0.12),
    0 16px 32px rgba(80, 50, 20, 0.14),
    0 32px 64px rgba(80, 50, 20, 0.1);
  position: relative;
}

.paper::before {
  content: "";
  position: absolute;
  top: 0;
  left: 56px;
  width: 1.5px;
  height: 100%;
  background: rgba(200, 90, 90, 0.22);
  pointer-events: none;
  z-index: 0;
}

.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    transparent,
    transparent 31px,
    rgba(140, 160, 200, 0.13) 31px,
    rgba(140, 160, 200, 0.13) 32px
  );
  pointer-events: none;
  border-radius: 3px;
  z-index: 0;
}

/* ── Title ─────────────────────────────────── */
.title {
  font-family: "Playfair Display", serif;
  font-size: 52px;
  font-weight: 700;
  color: #2a1a08;
  text-align: center;
  margin-bottom: 0.2rem;
  position: relative;
  z-index: 1;
  letter-spacing: 2px;
}

.subtitle {
  font-size: 14px;
  color: #a08060;
  text-align: center;
  margin-bottom: 2.5rem;
  position: relative;
  z-index: 1;
  font-style: italic;
  letter-spacing: 0.03em;
}

/* ── Setup ─────────────────────────────────── */
#setup-view {
  position: relative;
  z-index: 1;
}

.section-label {
  font-family: "Playfair Display", serif;
  font-size: 22px;
  color: #4e3218;
  margin-bottom: 1rem;
}

.players-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 2rem;
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  color: #a08060;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 7px;
}

input[type="text"] {
  width: 100%;
  padding: 9px 4px;
  font-size: 17px;
  font-family: "Source Sans 3", sans-serif;
  font-weight: 400;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid #c4a882;
  color: #2a1a08;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-bottom-color: #6b4422;
}
input[type="text"]::placeholder {
  color: #d0bc9e;
}

.btn {
  font-family: "Source Sans 3", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 11px 28px;
  border-radius: 4px;
  border: 2px solid #6b4422;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: #6b4422;
  color: #fefcf5;
}
.btn-primary:hover {
  background: #4e3218;
  border-color: #4e3218;
}

.error-msg {
  color: #a32d2d;
  font-size: 13px;
  margin-top: 10px;
  font-style: italic;
}

/* ── Game view ─────────────────────────────── */
#game-view {
  position: relative;
  z-index: 1;
}

/* ── Main score table ──────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

thead th {
  background: #ede0ca;
  font-size: 12px;
  font-weight: 700;
  color: #7a5830;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 11px 14px;
  border: 1px solid #d4b896;
  white-space: nowrap;
}
thead th:first-child {
  text-align: left;
}

.game-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.game-header .g-icon {
  font-size: 18px;
}
.game-header .g-label {
  font-size: 11px;
}

tbody td {
  border: 1px solid #ddd0bb;
  padding: 11px 14px;
  text-align: center;
  color: #2a1a08;
  background: #fefcf5;
  font-size: 15px;
}

tbody td.player-col {
  text-align: left;
  font-family: "Playfair Display", serif;
  font-size: 18px;
  font-weight: 600;
  color: #2a1a08;
  background: #f7efe0;
  white-space: nowrap;
  min-width: 90px;
}

tbody td.total-col {
  font-weight: 700;
  font-family: "Playfair Display", serif;
  font-size: 18px;
  background: #ede0ca;
}

tbody td.winning {
  background: #e4f0d8;
  color: #2e6010;
}

tbody td.game-cell {
  cursor: pointer;
  transition: background 0.13s;
}
tbody td.game-cell:hover {
  background: #f0e2c8;
}
tbody td.game-cell.selected {
  background: #f5e8cc;
  outline: 2px solid #6b4422;
  outline-offset: -2px;
}
tbody td.game-cell.played {
  cursor: default;
  color: #b89070;
  font-size: 16px;
  font-weight: 700;
}
tbody td.game-cell.not-turn {
  cursor: not-allowed;
  opacity: 0.45;
}

/* ── Score entry row ────────────────────────── */
tbody tr.score-entry td {
  background: #fffdf5;
  padding: 16px 20px;
}

.entry-label {
  font-family: "Playfair Display", serif;
  font-size: 17px;
  color: #4e3218;
  margin-bottom: 14px;
}

.entry-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 14px;
}

.entry-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 72px;
}

.entry-field .ef-label {
  font-size: 11px;
  font-weight: 700;
  color: #a08060;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.entry-field input[type="number"] {
  width: 68px;
  padding: 6px 8px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  border: none;
  border-bottom: 2px solid #c4a882;
  background: transparent;
  color: #2a1a08;
  outline: none;
  -moz-appearance: textfield;
}
.entry-field input[type="number"]::-webkit-inner-spin-button,
.entry-field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
.entry-field input[type="number"]:focus {
  border-bottom-color: #6b4422;
}

.entry-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-sm {
  font-size: 14px;
  padding: 8px 20px;
}

.btn-ghost {
  background: transparent;
  color: #7a5830;
  border-color: #c4a882;
  border-width: 1.5px;
}
.btn-ghost:hover {
  background: #f0e2c8;
}

/* ── Divider ────────────────────────────────── */
.section-divider {
  border: none;
  border-top: 1px dashed #c4a882;
  margin: 2rem 0 1.5rem;
}

/* ── History section ────────────────────────── */
.history-title {
  font-family: "Playfair Display", serif;
  font-size: 22px;
  color: #4e3218;
  margin-bottom: 1rem;
}

.round-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 0;
}

.round-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: #7a5830;
  padding: 8px 14px;
  border-radius: 4px;
  background: #f5ead4;
  border: 1px solid #e2caa8;
}

.round-item button {
  background: none;
  border: none;
  cursor: pointer;
  color: #c4a882;
  font-size: 16px;
  line-height: 1;
  padding: 0 3px;
}
.round-item button:hover {
  color: #a32d2d;
}

/* ── Totals summary table ───────────────────── */
.totals-title {
  font-family: "Playfair Display", serif;
  font-size: 22px;
  color: #4e3218;
  margin-bottom: 1rem;
}

.totals-table-wrap {
  overflow-x: auto;
}

.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.totals-table thead th {
  background: #ede0ca;
  font-size: 12px;
  font-weight: 700;
  color: #7a5830;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 11px 14px;
  border: 1px solid #d4b896;
  text-align: center;
}
.totals-table thead th:first-child {
  text-align: left;
}

.totals-table tbody td {
  border: 1px solid #ddd0bb;
  padding: 12px 14px;
  text-align: center;
  color: #2a1a08;
  background: #fefcf5;
  font-size: 15px;
}
.totals-table tbody td.tt-name {
  text-align: left;
  font-family: "Playfair Display", serif;
  font-size: 18px;
  font-weight: 600;
  background: #f7efe0;
}
.totals-table tbody td.tt-total {
  font-weight: 700;
  font-family: "Playfair Display", serif;
  font-size: 19px;
  background: #ede0ca;
}
.totals-table tbody td.tt-winner {
  background: #e4f0d8;
  color: #2e6010;
  font-family: "Playfair Display", serif;
  font-size: 19px;
  font-weight: 700;
}

/* ── Reset btn ─────────────────────────────── */
.reset-btn {
  font-size: 13px;
  color: #a08060;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  font-style: italic;
  float: right;
  margin-top: 1.5rem;
}
.reset-btn:hover {
  color: #6b4422;
}

.hidden {
  display: none;
}

/* ── Hint text ─────────────────────────────── */
.hint-text {
  font-size: 13px;
  color: #a08060;
  font-style: italic;
  margin-bottom: 1.25rem;
}

/* ── Details/summary ────────────────────────── */
details summary::-webkit-details-marker {
  color: #a08060;
}
details[open] summary {
  margin-bottom: 0.5rem;
}

/* ── Mobile ─────────────────────────────────── */
@media (max-width: 600px) {
  body {
    padding: 1rem 0.4rem 2rem;
  }

  .paper {
    padding: 1.75rem 1.1rem 2rem;
    border-radius: 2px;
  }
  .paper::before {
    left: 28px;
  }

  .title {
    font-size: 38px;
  }
  .subtitle {
    font-size: 13px;
    margin-bottom: 1.75rem;
  }
  .players-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .table-wrap,
  .totals-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table,
  .totals-table {
    font-size: 13px;
    min-width: 480px;
  }

  thead th {
    padding: 8px 8px;
    font-size: 10px;
  }
  .game-header .g-icon {
    font-size: 15px;
  }
  .game-header .g-label {
    font-size: 9px;
  }

  tbody td {
    padding: 9px 8px;
    font-size: 13px;
  }
  tbody td.player-col {
    font-size: 15px;
    min-width: 70px;
  }
  tbody td.total-col {
    font-size: 15px;
  }

  .totals-table thead th {
    padding: 8px 8px;
  }
  .totals-table tbody td {
    padding: 9px 8px;
  }
  .totals-table tbody td.tt-name {
    font-size: 14px;
  }
  .totals-table tbody td.tt-total,
  .totals-table tbody td.tt-winner {
    font-size: 15px;
  }

  .entry-inputs {
    gap: 14px;
  }
  .entry-field input[type="number"] {
    width: 56px;
    font-size: 18px;
  }

  .history-title {
    font-size: 19px;
  }
  .hint-text {
    font-size: 12px;
  }
  .reset-btn {
    font-size: 12px;
  }
}

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 26, 8, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-box {
  background: #fefcf5;
  border-radius: 6px;
  padding: 2rem 2.25rem;
  max-width: 360px;
  width: 90%;
  box-shadow:
    0 4px 12px rgba(42, 26, 8, 0.15),
    0 16px 40px rgba(42, 26, 8, 0.18);
  animation: slideUp 0.18s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-title {
  font-family: "Playfair Display", serif;
  font-size: 22px;
  color: #2a1a08;
  margin-bottom: 0.6rem;
}

.modal-body {
  font-size: 14px;
  color: #7a5830;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-ghost-modal {
  background: transparent;
  color: #7a5830;
  border-color: #c4a882;
  border-width: 1.5px;
  font-size: 13px;
  padding: 8px 18px;
}
.btn-ghost-modal:hover {
  background: #f0e2c8;
}

.btn-danger {
  background: #a32d2d;
  color: #fefcf5;
  border-color: #a32d2d;
  font-size: 13px;
  padding: 8px 18px;
}
.btn-danger:hover {
  background: #7d2020;
  border-color: #7d2020;
}
