/* TeamQuest – Mobile-First & Classroom Print Stylesheet */
:root {
  --tq-bg: #f1f5f9;
  --tq-surface: #ffffff;
  --tq-dark: #0f172a;
  --tq-primary: #0f766e;
  --tq-sky: #0284c7;
  --tq-amber: #d97706;
  --tq-danger: #dc2626;
  --tq-border: #e2e8f0;
  --tq-muted: #64748b;
  --tq-radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--tq-bg);
  color: var(--tq-dark);
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  margin: 0;
}

.tq-topbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--tq-border);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.tq-topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tq-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--tq-dark);
  font-weight: 800;
  font-size: 1.1rem;
}

.tq-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #f0fdfa;
  color: var(--tq-primary);
  border: 1px solid #99f6e4;
}

.tq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.94rem;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
}

.tq-btn:active { transform: scale(0.98); }
.tq-btn-primary { background: var(--tq-primary); color: #ffffff; }
.tq-btn-primary:hover { filter: brightness(0.92); }
.tq-btn-sky { background: var(--tq-sky); color: #ffffff; }
.tq-btn-sky:hover { filter: brightness(0.92); }
.tq-btn-outline { background: #ffffff; color: #334155; border-color: #cbd5e1; }
.tq-btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }
.tq-btn-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.tq-btn-sm { min-height: 36px; padding: 7px 12px; font-size: 0.82rem; border-radius: 9px; }

/* Join / Landing Card */
.tq-join-wrap {
  max-width: 520px;
  margin: 42px auto;
  padding: 0 16px 80px;
}

.tq-card {
  background: var(--tq-surface);
  border: 1px solid var(--tq-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.tq-code-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--tq-dark);
}

.tq-code-input:focus {
  outline: none;
  border-color: var(--tq-primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

/* Main Game Layout (Mobile-First & iPad Friendly) */
.tq-game-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 14px calc(88px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 960px) {
  .tq-game-shell {
    grid-template-columns: 1.25fr 1fr;
    align-items: start;
    padding: 20px 20px calc(88px + env(safe-area-inset-bottom, 0px));
  }
}

.tq-world-card {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #cbd5e1;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tq-world-canvas {
  width: 100%;
  height: 290px;
  display: block;
}

@media (min-width: 640px) {
  .tq-world-canvas {
    height: 370px;
  }
}

@media (min-width: 960px) {
  .tq-world-canvas {
    height: 460px;
  }
}

.tq-world-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.tq-hud-pill {
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tq-world-hint {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  font-size: 0.7rem;
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}

.tq-cam-bar {
  position: absolute;
  bottom: 8px;
  left: 10px;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  max-width: calc(100% - 20px);
  z-index: 4;
}

.tq-cam-btn {
  background: rgba(15, 23, 42, 0.76);
  backdrop-filter: blur(8px);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
}

.tq-cam-btn:hover,
.tq-cam-btn.active {
  background: #0284c7;
  border-color: #7dd3fc;
  color: #ffffff;
}

@media (max-width: 640px) {
  .tq-world-hint {
    display: none;
  }
}

/* Status & Resource Strip */
.tq-res-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.tq-res-box {
  background: #f8fafc;
  border: 1px solid var(--tq-border);
  border-radius: 12px;
  padding: 9px 10px;
  text-align: center;
}

.tq-res-val {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--tq-dark);
  display: block;
}

.tq-res-lbl {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--tq-muted);
}

/* Buildings List */
.tq-building-card {
  background: #ffffff;
  border: 1px solid var(--tq-border);
  border-radius: 14px;
  padding: 13px 14px;
  margin-bottom: 10px;
}

.tq-building-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tq-prog-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 600;
}

@media (max-width: 440px) {
  .tq-prog-row {
    grid-template-columns: 1fr auto;
    row-gap: 5px;
  }
  .tq-prog-row .tq-prog-track {
    grid-column: 1 / -1;
    order: 3;
  }
}

/* Prevent iOS Safari auto-zoom on form controls */
@media (max-width: 1024px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

.tq-prog-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.tq-prog-fill {
  height: 100%;
  background: linear-gradient(90deg, #0f766e, #0284c7);
  transition: width 0.25s ease;
}

/* Journal & Ticker */
.tq-journal-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 0.86rem;
}

.tq-events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 220px;
  overflow-y: auto;
}

.tq-event-item {
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.83rem;
  color: #334155;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* Modal */
.tq-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.tq-modal-backdrop.open { display: flex; }

.tq-modal-box {
  background: #ffffff;
  border-radius: 22px;
  max-width: 540px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
  position: relative;
}

.tq-role-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 14px 0;
}

.tq-role-btn {
  text-align: left;
  padding: 14px;
  border-radius: 14px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.tq-role-btn:hover {
  border-color: var(--tq-primary);
  background: #f0fdfa;
}

/* Multiple-Choice Option Buttons */
.tq-mc-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.tq-mc-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  font-size: 0.94rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
  transition: all 0.14s ease;
}

.tq-mc-btn:hover:not(:disabled) {
  border-color: #0284c7;
  background: #f0f9ff;
}

.tq-mc-btn:disabled {
  cursor: default;
}

.tq-mc-btn.correct {
  border-color: #16a34a;
  background: #dcfce7;
  color: #14532d;
}

.tq-mc-btn.wrong {
  border-color: #dc2626;
  background: #fee2e2;
  color: #7f1d1d;
}

.tq-mc-letter {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #e2e8f0;
  color: #334155;
  font-size: 0.8rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Printable A4 Code Cards */
.tq-print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.tq-ticket {
  background: #ffffff;
  border: 1.5px dashed #94a3b8;
  border-radius: 12px;
  padding: 12px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.tq-ticket-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.tq-ticket-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--tq-primary);
  letter-spacing: 0.8px;
}

@media print {
  .no-print, .tq-topbar, #cmschule-badge-placeholder {
    display: none !important;
  }
  body {
    background: #ffffff !important;
  }
  .tq-print-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}
