/* ============================================================
   Compass Quest — styles (screen + A4 print)
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #2c2318;
  --paper: #fdf6e3;
  --gold: #f5b942;
  --sea: #79c4dd;
  --red: #d64545;
  --green: #3f9d63;
}

html, body { height: 100%; }
body {
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, #ffe9b8 0%, transparent 60%),
    linear-gradient(180deg, #f7e7c3 0%, #efd9a7 45%, #d9ecf5 100%);
  min-height: 100vh;
}

/* ---------------- screens ---------------- */
.screen { display: none; min-height: 100vh; padding: 20px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

.card {
  background: var(--paper);
  border: 3px solid #b98d4f;
  border-radius: 18px;
  box-shadow: 0 10px 26px rgba(70, 45, 10, 0.22), inset 0 0 0 4px rgba(255, 255, 255, 0.5);
  padding: 22px;
}

/* ---------------- start screen ---------------- */
#screen-start { justify-content: flex-start; }
.start-wrap {
  display: grid;
  grid-template-columns: minmax(320px, 640px) minmax(220px, 300px);
  gap: 18px;
  width: 100%;
  max-width: 980px;
  align-items: start;
}
@media (max-width: 760px) { .start-wrap { grid-template-columns: 1fr; } }

.start-card h1.game-title {
  font-size: clamp(30px, 5vw, 44px);
  letter-spacing: 1px;
  color: #5b3a1e;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.7);
}
.start-card .flag { display: inline-block; transform: rotate(-8deg); }
.tagline { margin: 6px 0 16px; font-size: 16px; color: #6b543a; }

.field { margin-bottom: 14px; }
.field label, .field .lbl { display: block; font-weight: bold; margin-bottom: 6px; }
#inp-name {
  width: 100%;
  font-size: 20px;
  padding: 10px 12px;
  border: 2px solid #b98d4f;
  border-radius: 10px;
  background: #fffdf6;
}
#inp-name.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.seg { display: inline-flex; border: 2px solid #b98d4f; border-radius: 10px; overflow: hidden; background: #fffdf6; }
.seg button {
  border: none; background: transparent; padding: 8px 14px; font-size: 15px; font-weight: bold;
  cursor: pointer; color: #6b543a;
}
.seg button + button { border-left: 2px solid #e0c795; }
.seg button.on { background: var(--gold); color: #4a2f10; }

.howto {
  font-size: 14.5px; line-height: 1.45; margin: 4px 0 16px; padding: 10px 12px;
  background: #fff3d6; border: 2px dashed #d8b06a; border-radius: 10px; color: #5c4527;
}

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.big-btn {
  font-size: 19px; font-weight: bold; padding: 13px 22px; border-radius: 14px; cursor: pointer;
  border: 3px solid #8a5a2e; background: linear-gradient(180deg, #ffd97a, #f5b942); color: #4a2f10;
  box-shadow: 0 5px 0 #a9762f, 0 8px 14px rgba(0,0,0,0.18);
  transition: transform 0.06s ease;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a9762f; }
.big-btn.primary { background: linear-gradient(180deg, #7ed49b, #3f9d63); border-color: #2c6e45; color: #fff; box-shadow: 0 5px 0 #2c6e45, 0 8px 14px rgba(0,0,0,0.18); }
.big-btn.primary:active { box-shadow: 0 2px 0 #2c6e45; }
.big-btn.ghost { background: linear-gradient(180deg, #fffdf6, #f3e6c8); border-color: #b98d4f; color: #5b3a1e; box-shadow: 0 5px 0 #b98d4f, 0 8px 14px rgba(0,0,0,0.12); }
.big-btn.danger { background: linear-gradient(180deg, #ef8a8a, #d64545); border-color: #9c2b2b; color: #fff; box-shadow: 0 5px 0 #9c2b2b, 0 8px 14px rgba(0,0,0,0.18); }
.big-btn:disabled { opacity: 0.6; cursor: wait; }

.top-sailors h3 { margin-bottom: 8px; color: #5b3a1e; }
.top-sailors ol { padding-left: 22px; font-size: 15px; line-height: 1.9; }
.muted { color: #8a7458; }

.icon-btn {
  border: none; background: transparent; cursor: pointer; font-size: 20px; padding: 6px;
  border-radius: 10px; line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.6); }

.admin-gear {
  position: fixed; top: 14px; right: 16px; z-index: 30;
  font-size: 17px; opacity: 0.85;
}

/* ---------------- HUD ---------------- */
.hud {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  width: 100%; max-width: 1120px; margin-bottom: 12px;
}
.hud-badge {
  background: var(--paper); border: 2px solid #b98d4f; border-radius: 999px;
  padding: 7px 14px; font-weight: bold; font-size: 15.5px; color: #4a3520;
}
.level-badge { background: linear-gradient(180deg, #ffe9ad, #f5b942); border-color: #a9762f; color: #4a2f10; font-size: 16.5px; }
.score-badge { background: #fffdf6; }
.hearts { letter-spacing: 2px; }
.timer.danger { background: #ffd9d9; border-color: var(--red); color: #8c1f1f; animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------------- game layout ---------------- */
.game-main {
  display: grid;
  grid-template-columns: minmax(320px, 740px) minmax(280px, 360px);
  gap: 16px;
  width: 100%;
  max-width: 1120px;
  align-items: start;
}
@media (max-width: 900px) {
  .game-main { grid-template-columns: 1fr; }
  .side-panel { order: -1; }
}

.map-wrap { position: relative; }
#map {
  width: 100%; height: auto; display: block;
  border: 4px solid #8a5a2e; border-radius: 16px;
  box-shadow: 0 12px 26px rgba(30, 60, 90, 0.3);
  background: #bfe8f5;
  touch-action: none;
}

.banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: rgba(253, 246, 227, 0.96); border: 3px solid #b98d4f; border-radius: 16px;
  padding: 16px 26px; font-size: clamp(18px, 3vw, 26px); font-weight: bold; text-align: center;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3); pointer-events: none; max-width: 90%;
}
.banner b { color: #2c6e45; }
.hidden { display: none !important; }

.side-panel { display: flex; flex-direction: column; gap: 14px; }

.prompt-card {
  background: var(--paper); border: 3px solid #b98d4f; border-radius: 16px; padding: 14px 16px;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,0.5);
}
.prompt-kicker { font-size: 12px; letter-spacing: 2px; color: #a9762f; font-weight: bold; }
#prompt-text { font-size: clamp(18px, 2.4vw, 23px); line-height: 1.35; margin-top: 4px; min-height: 2.6em; }

/* ---------------- compass pad ---------------- */
.compass-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 340px);
  margin: 0 auto;
}
.pad-btn {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 3px solid #8a5a2e;
  background: radial-gradient(circle at 32% 30%, #fff6dd, #f0d9a4);
  font-size: clamp(20px, 3vw, 27px);
  font-weight: bold; color: #4a2f10;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
  box-shadow: 0 4px 0 #b98d4f, 0 6px 10px rgba(0,0,0,0.15);
  display: flex; align-items: center; justify-content: center;
}
.pad-btn i {
  position: absolute; bottom: 7%; font-style: normal; font-size: 11px; letter-spacing: 1px; color: #8a6d3b;
}
.pad-btn.card { background: radial-gradient(circle at 32% 30%, #eafff0, #cdeec9); }
.pad-btn.diag { background: radial-gradient(circle at 32% 30%, #fff1e4, #f6d7b8); }
.pad-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b98d4f; }

.pad-center {
  display: flex; align-items: center; justify-content: center; font-size: clamp(26px, 4vw, 38px);
}

.game-hint { margin-top: 12px; color: #7a5c33; font-size: 14px; text-align: center; }

/* ---------------- end screen ---------------- */
.end-card { width: min(96%, 620px); text-align: center; margin-top: 4vh; }
.end-card h2 { color: #5b3a1e; font-size: clamp(26px, 4.5vw, 38px); }
.final-score { margin: 18px auto; display: inline-block; background: #fff3d6; border: 3px dashed #d8b06a; border-radius: 16px; padding: 12px 34px; }
.fs-label { display: block; font-size: 14px; letter-spacing: 2px; color: #8a6d3b; text-transform: uppercase; }
.fs-value { font-size: 54px; font-weight: bold; color: #2c6e45; line-height: 1.05; }

.lb-table { width: 100%; border-collapse: collapse; margin: 14px auto 20px; background: #fffdf6; border-radius: 12px; overflow: hidden; }
.lb-table th, .lb-table td { padding: 9px 12px; text-align: left; font-size: 15.5px; }
.lb-table thead { background: linear-gradient(180deg, #ffe9ad, #f5d78a); color: #4a2f10; }
.lb-table tbody tr:nth-child(even) { background: #faf3e2; }
.lb-table tr.me td { background: #dff3e6 !important; font-weight: bold; }

/* ---------------- modals ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(40, 28, 10, 0.55); padding: 16px;
}
.modal-card { width: min(94%, 430px); }
.modal-card h3 { color: #5b3a1e; margin-bottom: 10px; font-size: 22px; }
.modal-card label { display: block; font-weight: bold; margin: 8px 0 6px; }
.modal-card input[type="password"] {
  width: 100%; padding: 10px 12px; font-size: 18px; letter-spacing: 3px;
  border: 2px solid #b98d4f; border-radius: 10px; background: #fffdf6;
}

/* ============================================================
   PRINT — A4 worksheet
   ============================================================ */
#print-sheet { display: none; }

@page { size: A4; margin: 12mm; }

@media print {
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet { display: block !important; color: #000; background: #fff; }
  .ws-page { font-family: "Trebuchet MS", Verdana, sans-serif; }

  .ws-header h1 { font-size: 24pt; margin-bottom: 2mm; }
  .ws-sub { font-size: 10.5pt; color: #333; }
  .ws-name { display: flex; justify-content: space-between; font-size: 11pt; margin-top: 4mm; }

  /* top half of page 1: map + key + compass */
  .ws-top {
    display: flex; gap: 6mm; align-items: stretch;
    border: 2.5px solid #8a6d3b; border-radius: 4mm; padding: 4mm;
    margin: 5mm 0 7mm 0; background: #fffdf6;
    break-inside: avoid; page-break-inside: avoid;
  }
  .ws-map-box { flex: 1.25; min-width: 0; display: flex; align-items: center; justify-content: center; }
  .ws-side { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3mm; }
  .ws-rose { width: 42mm !important; height: 42mm !important; }

  .ws-key h4 { font-size: 12pt; margin-bottom: 1.5mm; color: #5b3a1e; }
  .ws-key ul { list-style: none; font-size: 9.8pt; line-height: 1.75; }
  .k-ico { display: inline-block; min-width: 16mm; }

  /* questions */
  .ws-questions { counter-reset: q; }
  .ws-q {
    display: flex; gap: 4mm; align-items: center;
    border-bottom: 1px solid #cbb98f; padding: 2.6mm 0;
    break-inside: avoid; page-break-inside: avoid;
  }
  .ws-q-left { display: flex; align-items: center; gap: 2mm; min-width: 34mm; font-size: 11pt; font-weight: bold; }
  .ws-minimap { width: 29mm !important; height: auto !important; border: 1.5px solid #8a6d3b; border-radius: 1.5mm; background: #cdeef7; }
  .ws-q-right { flex: 1; min-width: 0; }
  .ws-prompt { font-size: 11pt; margin-bottom: 1.8mm; line-height: 1.3; }

  .ws-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(42mm, 1fr)); gap: 1.5mm 6mm; }
  .ws-opt { display: flex; align-items: center; gap: 2mm; font-size: 10.5pt; white-space: nowrap; }
  .ws-opt .box {
    width: 4.6mm; height: 4.6mm; border: 1.6px solid #333; display: inline-block; flex: none;
    background: #fff;
  }

  .ws-key-footer { margin-top: 8mm; font-size: 9pt; color: #222; border-top: 2px solid #8a6d3b; padding-top: 2.5mm; }
}
