* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
}

@media (min-width: 701px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .game-screen {
    height: 100vh;
    overflow: hidden;
  }
}

@media (max-width: 700px) {
  html,
  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .game-screen {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
}


body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  color: #292722;
  background: radial-gradient(circle at 20% 20%, rgba(255,255,255,0.5), transparent 35%), #cdc2ae;
}

.site-header {
  padding: 20px;
  text-align: center;
  background: white;
  border-bottom: 1px solid #ddd8cf;
}

.site-header h1 {
  margin: 0;
  font-size: 32px;
}

.site-header p {
  margin: 6px 0 0;
  color: #777064;
}

.hidden {
  display: none !important;
}

/* Start screen */

.start-screen {
  width: min(500px, calc(100% - 32px));
  margin: 80px auto;
}

.start-card {
  padding: 40px;
  text-align: center;
  background: white;
  border: 1px solid #ddd8cf;
  border-radius: 12px;
}

.start-card h2 {
  margin-top: 0;
}

.start-card p {
  margin-bottom: 28px;
  color: #777064;
  line-height: 1.5;
}

.start-button {
  padding: 12px 24px;
  border: 0;
  border-radius: 7px;
  background: #292722;
  color: white;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.start-button:hover {
  background: #44413a;
}

/* Game */

.game-screen {
  width: min(1100px, calc(100% - 32px));
  height: 100vh;
  margin: 0 auto;
  padding: 30px 0;
  overflow: hidden;
}

/* Cards */

.game-card {
  margin-bottom: 16px;
  background: #fffefa;
  border: 1px solid #ddd8cf;
  border-radius: 10px;
}

/* Goals */

.goals-card {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
}

.goal {
  min-width: 0;
}

.goal-end {
  text-align: right;
}

.goal-label,
.timer-label {
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #8a8275;
}

.page-name {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  font-weight: bold;
}

.goal-arrow {
  color: #aaa092;
  font-size: 20px;
}

.timer {
  padding-left: 16px;
  border-left: 1px solid #ddd8cf;
  text-align: right;
}

#timer {
  font-size: 18px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

/* Game content */

.game-content {
  display: grid;
  grid-template-columns: minmax(0, 0.3fr) minmax(0, 1fr) minmax(0, 0.3fr);
  gap: 16px;
  align-items: start;
}

/* Card headers */

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #e2ddd4;
}

.card-header h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.card-header span {
  color: #91897d;
  font-size: 12px;
}

/* Table of contents */

.toc-card {
  height: 600px;
  overflow: hidden;
}

.table-of-contents {
  height: 560px;
  padding: 10px;
  overflow-y: auto;
}

.toc-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #777064;
  font-family: Arial, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.toc-item:hover {
  background: #f0ebe2;
  color: #292722;
}

.toc-item.active {
  background: #e5ded2;
  color: #292722;
  font-weight: bold;
}

.toc-subitem {
  padding-left: 24px;
  font-size: 12px;
}

/* Wikipedia */

.wikipedia-card {
  min-width: 0;
  overflow: hidden;
}

.wikipedia-container {
  height: 560px;
  padding: 30px;
  overflow: auto;
  background: #fff;
  font-family: Georgia, serif;
  font-size: 16px;
  line-height: 1.7;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

.wikipedia-container > * {
  max-width: none;
}

.wikipedia-container p {
  margin: 0 0 16px;
}

.wikipedia-container table {
  border-collapse: collapse;
  margin: 20px 0;
}

.wikipedia-container th,
.wikipedia-container td {
  padding: 8px 12px;
  border: 1px solid #aaa;
  text-align: left;
  vertical-align: top;
}

.wikipedia-container th {
  background: #eee;
  font-weight: bold;
}

.wikipedia-container img {
  max-width: none;
  height: auto;
}

.wikipedia-container h1,
.wikipedia-container h2,
.wikipedia-container h3 {
  line-height: 1.3;
}

.wikipedia-container h1 {
  font-size: 30px;
}

.wikipedia-container h2 {
  margin-top: 28px;
  padding-bottom: 6px;
  border-bottom: 1px solid #ccc;
}

.wikipedia-container h3 {
  font-size: 20px;
}

/* Navigation */

.navigation-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e2ddd4;
}

.nav-button {
  padding: 10px;
  border: 1px solid #d6d0c6;
  border-radius: 6px;
  background: white;
  color: #292722;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
}

.nav-button:hover:not(:disabled) {
  background: #f0ebe2;
}

.nav-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Wikipedia links */

.wiki-link {
  padding: 0;
  border: 0;
  background: none;
  color: #4267a8;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.wiki-link:hover {
  color: #234f8c;
}

/* Path */

.path-card {
  height: 600px;
  overflow: hidden;
}

.path-list {
  height: 560px;
  padding: 10px;
  overflow-y: auto;
}

.path-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border-radius: 6px;
}

.path-item.current {
  background: #f0ebe2;
}

.path-number {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #ded6c9;
  font-size: 12px;
  font-weight: bold;
}

.path-page {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

/* Completion screen */

.completion-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.completion-screen.hidden {
  display: none !important;
}

.completion-overlay {
  position: absolute;
  inset: 0;
  background: rgba(41, 39, 34, 0.5);
  backdrop-filter: blur(3px);
}

.completion-card {
  position: relative;
  z-index: 1;
  width: min(520px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 32px;
  background: #fffefa;
  border: 1px solid #ddd8cf;
  border-radius: 12px;
  box-shadow: 0 15px 40px rgba(41, 39, 34, 0.25);
}

.completion-card h2 {
  margin: 0 0 24px;
  text-align: center;
  font-size: 28px;
}

.completion-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.completion-stat {
  padding: 16px 8px;
  text-align: center;
  background: #f5f1e9;
  border: 1px solid #ddd8cf;
  border-radius: 8px;
}

.completion-stat .stat-label {
  display: block;
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #8a8275;
}

.completion-stat strong {
  font-size: 22px;
}

.completion-path .stat-label {
  display: block;
  margin-bottom: 8px;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #8a8275;
}

.completion-path-item {
  padding: 8px 10px;
  border-bottom: 1px solid #e2ddd4;
  font-size: 14px;
}

/* MOBILE SCROLL OVERRIDE */
@media screen and (max-width: 700px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .game-screen {
    width: calc(100% - 20px);
    margin: 0 auto;
    padding: 20px 0 40px;
    overflow: visible;
  }

  .game-content {
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
    gap: 16px;
    overflow: visible;
  }

  .game-content .toc-card,
  .game-content .wikipedia-card,
  .game-content .path-card {
    width: 100% !important;
    min-width: 0 !important;
    margin: 0;
  }

  .game-content .toc-card {
    height: auto !important;
    overflow: hidden;
  }

  .game-content .table-of-contents {
    height: 180px;
    overflow-y: auto;
  }

  .game-content .wikipedia-card {
    height: auto !important;
    overflow: hidden;
  }

  .game-content .wikipedia-container {
    height: 500px !important;
    max-height: 500px !important;
    overflow-x: auto;
    overflow-y: auto;
  }

  .game-content .path-card {
    height: auto !important;
    overflow: hidden;
  }

  .game-content .path-list {
    height: 150px;
    overflow-y: auto;
  }
}

@media screen and (max-width: 400px) {
  .game-content .wikipedia-container {
    height: 380px !important;
    max-height: 380px !important;
  }
}