:root {
  --red: #ef4444;
  --red-dark: #b91c1c;
  --red-soft: #fee2e2;
  --blue: #3b82f6;
  --blue-dark: #1d4ed8;
  --blue-soft: #dbeafe;
  --ink: #172033;
  --muted: #64748b;
  --panel: rgba(255, 255, 255, 0.95);
  --line: rgba(148, 163, 184, 0.24);
  --shadow: 0 22px 55px rgba(15, 23, 42, 0.17);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgba(239, 68, 68, .23), transparent 30%),
    radial-gradient(circle at 92% 13%, rgba(59, 130, 246, .23), transparent 30%),
    linear-gradient(145deg, #fff7f7 0%, #f8fafc 48%, #f2f7ff 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image:
    linear-gradient(rgba(15,23,42,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15,23,42,.04) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 75%);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.app-shell {
  width: min(1460px, 100%);
  margin: 0 auto;
  padding: 18px;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--red) 0 48%, var(--blue) 52% 100%);
  border: 3px solid rgba(255,255,255,.92);
  font-size: 28px;
  box-shadow: 0 10px 24px rgba(15,23,42,.18);
}
.brand h1 { margin: 0; font-size: 25px; letter-spacing: -.7px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 43px;
  height: 43px;
  border: 1px solid rgba(255,255,255,.88);
  border-radius: 13px;
  background: rgba(255,255,255,.78);
  box-shadow: 0 7px 18px rgba(15,23,42,.10);
  color: var(--ink);
  font-weight: 900;
  backdrop-filter: blur(12px);
  transition: transform .16s ease, box-shadow .16s ease;
}
.icon-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 25px rgba(15,23,42,.15); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(270px, 21vw, 320px);
  gap: 15px;
  align-items: stretch;
  min-width: 0;
}

.game-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-radius: 25px;
  background: #0f172a;
  box-shadow: var(--shadow);
  min-height: 0;
  aspect-ratio: 5 / 3;
  border: 4px solid rgba(255,255,255,.82);
}

.game-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(15,23,42,.24), inset 0 -18px 45px rgba(15,23,42,.09);
  border-radius: inherit;
}

canvas { width: 100%; height: 100%; display: block; image-rendering: auto; }

.side-card {
  min-width: 0;
  border-radius: 24px;
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid rgba(255,255,255,.9);
}

.app-shell.orders-hidden .game-layout {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.orders-hidden .side-card {
  display: none;
}

#panelBtn.panel-hidden {
  background: rgba(219, 234, 254, .94);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, .18), 0 7px 18px rgba(15,23,42,.10);
}

.side-section { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.side-section:last-child { border-bottom: 0; padding-bottom: 0; }
.side-section h3 { margin: 0 0 10px; font-size: 15px; letter-spacing: -.2px; }

.orders-panel {
  display: grid;
  gap: 11px;
  max-height: 335px;
  overflow: auto;
  padding-right: 3px;
  scrollbar-width: thin;
}
.team-orders { display: grid; gap: 7px; }
.team-orders-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 900;
}
.team-orders-title b { font-size: 9px; opacity: .74; text-transform: uppercase; }
.team-orders.team-0 .team-orders-title { color: var(--red-dark); background: var(--red-soft); }
.team-orders.team-1 .team-orders-title { color: var(--blue-dark); background: var(--blue-soft); }

.order-card {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  padding: 9px;
  background: rgba(255,255,255,.96);
  display: grid;
  grid-template-columns: 39px 1fr;
  align-items: center;
  gap: 8px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 5px 13px rgba(15,23,42,.07);
  transition: transform .15s ease;
}
.order-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}
.order-card.team-0::before { background: var(--red); }
.order-card.team-1::before { background: var(--blue); }
.order-card.warning { animation: orderPulse 1.15s infinite alternate; }
.order-card.urgent { border-color: rgba(239,68,68,.48); animation: urgentShake .55s infinite alternate; }
.order-card .emoji { font-size: 28px; text-align: center; }
.order-card strong { display: block; font-size: 12px; }
.order-card small { display: block; color: var(--muted); font-size: 10px; margin-top: 1px; }
.order-progress { height: 6px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.order-progress i { display: block; height: 100%; background: #22c55e; border-radius: inherit; transition: width .2s linear; }
.order-card.warning .order-progress i { background: #f59e0b; }
.order-card.urgent .order-progress i { background: var(--red); }
.empty-state { color: var(--muted); font-size: 12px; margin: 0; padding: 5px 1px; }

@keyframes orderPulse { from { box-shadow: 0 4px 12px rgba(245,158,11,.06); } to { box-shadow: 0 6px 18px rgba(245,158,11,.20); } }
@keyframes urgentShake { from { transform: translateX(-1px); } to { transform: translateX(1px); } }

.recipe { display: flex; gap: 9px; align-items: center; margin-bottom: 9px; }
.recipe > span {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #fff7ed, #f1f5f9);
  border: 1px solid #e2e8f0;
  font-size: 22px;
}
.recipe strong, .recipe small { display: block; }
.recipe strong { font-size: 12px; }
.recipe small { color: var(--muted); font-size: 10px; }
.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; font-size: 11px; }
.legend-grid span { padding: 7px; border-radius: 9px; background: #f1f5f9; border: 1px solid #e2e8f0; }

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(15,23,42,.74);
  backdrop-filter: blur(8px);
  padding: 20px;
  z-index: 10;
}
.overlay.show { display: grid; }
.panel {
  width: min(700px, 100%);
  max-height: 94%;
  overflow: auto;
  padding: 27px;
  border-radius: 25px;
  background: var(--panel);
  box-shadow: 0 25px 70px rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.95);
  text-align: center;
}
.menu-panel { width: min(760px, 100%); }
.logo-big {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  margin: 0 auto 6px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--red-soft), white 48%, var(--blue-soft));
  border: 1px solid #e2e8f0;
  font-size: 47px;
  box-shadow: 0 12px 30px rgba(15,23,42,.12);
}
.panel h2 { margin: 0; font-size: 32px; letter-spacing: -1px; }
.subtitle { color: var(--muted); margin: 7px 0 20px; }
.selector-group { margin: 0 auto 18px; max-width: 390px; }
.selector-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: #e2e8f0; border-radius: 14px; padding: 4px; }
.mode-btn { border: 0; border-radius: 11px; padding: 10px; background: transparent; font-weight: 900; color: var(--muted); }
.mode-btn.active {
  background: white;
  color: var(--red-dark);
  box-shadow: 0 4px 12px rgba(15,23,42,.12), inset -3px 0 0 var(--blue), inset 3px 0 0 var(--red);
}
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-action {
  border: 2px solid #e2e8f0;
  background: white;
  border-radius: 17px;
  padding: 13px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.menu-action:hover { transform: translateY(-2px); border-color: #93c5fd; box-shadow: 0 10px 24px rgba(15,23,42,.12); }
.menu-action.primary { border-color: rgba(239,68,68,.5); background: linear-gradient(135deg, var(--red-soft), white 58%, var(--blue-soft)); }
.action-icon { font-size: 26px; }
.menu-action strong, .menu-action small { display: block; }
.menu-action small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.legal-note { color: #94a3b8; font-size: 10px; margin: 15px 0 0; }

button:not(.icon-btn):not(.mode-btn):not(.menu-action):not(.text-btn) {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  background: #e2e8f0;
  font-weight: 900;
  color: var(--ink);
}
button.primary { background: linear-gradient(135deg, var(--red), #dc2626 48%, var(--blue)) !important; color: white !important; }
button.danger { background: var(--red-soft) !important; color: var(--red-dark) !important; }
button.wide { width: 100%; margin-top: 9px; }
.text-btn { border: 0; background: transparent; color: var(--muted); margin-top: 13px; }

.room-panel { width: min(500px, 100%); }
.room-panel > p { color: var(--muted); }
.room-box { margin-top: 16px; }
.room-box.hidden { display: none; }
.room-code-row { display: flex; justify-content: center; align-items: center; gap: 9px; margin: 8px 0 14px; }
.room-code-row strong { font-size: 32px; letter-spacing: 5px; color: var(--blue-dark); }
.room-code-row button { padding: 8px 11px !important; }
.player-slots { display: grid; gap: 7px; text-align: left; }
.player-slot { padding: 9px 12px; border-radius: 10px; background: #f1f5f9; display: flex; justify-content: space-between; font-size: 13px; }
.player-slot.ready { background: #dcfce7; color: #166534; }
.room-box input {
  width: 100%;
  border: 2px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin: 8px 0;
  outline: none;
}
.room-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(59,130,246,.13); }

.compact-panel { width: min(360px, 100%); }
.compact-panel h2 { font-size: 26px; margin-bottom: 12px; }
.result-emoji { font-size: 58px; }
.end-panel { width: min(470px, 100%); }
.end-panel h2 { font-size: 30px; }
#resultScore { font-size: 44px; font-weight: 900; margin: 10px 0 18px; }
.result-actions { display: flex; justify-content: center; gap: 10px; }

.help-panel { width: min(650px, 100%); text-align: left; }
.help-panel h2 { text-align: center; }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 18px 0; }
.controls-grid div { background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 13px; padding: 12px; }
.controls-grid strong, .controls-grid span { display: block; }
.controls-grid span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.how-to-play { background: linear-gradient(135deg, var(--red-soft), white 48%, var(--blue-soft)); border-radius: 13px; padding: 12px; }
.how-to-play h3 { margin: 0 0 5px; }
.how-to-play p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #0f172a;
  color: white;
  border-radius: 12px;
  padding: 10px 15px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 50;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; padding: 10px 4px 0; }

@media (max-width: 1420px) {
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .side-card {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(210px, .8fr) minmax(210px, .8fr);
    align-items: start;
  }
  .side-section {
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding: 0 14px 0 0;
  }
  .side-section:last-child { border-right: 0; padding-right: 0; }
  .orders-panel { max-height: 255px; }
}

@media (max-width: 930px) {
  .side-card { grid-template-columns: 1fr; }
  .side-section {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 13px;
  }
  .side-section:last-child { border-bottom: 0; }
}

@media (max-width: 720px) {
  .app-shell { padding: 8px; }
  .brand p { display: none; }
  .brand-icon { width: 46px; height: 46px; border-radius: 14px; }
  .game-card { min-height: 0; border-radius: 17px; border-width: 2px; }
  .menu-grid, .controls-grid, .side-card { grid-template-columns: 1fr; }
  .side-section { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; }
  .panel { padding: 18px; border-radius: 18px; }
  .panel h2 { font-size: 27px; }
  .menu-action { padding: 10px; }
  footer { flex-direction: column; }
  .result-actions { flex-direction: column; }
}


/* ---------- Modo historia ---------- */
.hidden { display: none !important; }
.story-action {
  border-color: rgba(124, 58, 237, .35) !important;
  background: linear-gradient(135deg, #f3e8ff, white 58%, #ffedd5) !important;
}
.story-panel {
  width: min(820px, 100%);
  text-align: left;
}
.story-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 16px;
}
.story-heading h2 { font-size: 29px; }
.story-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.story-book {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: linear-gradient(145deg, #ede9fe, #fff7ed);
  border: 1px solid #ddd6fe;
  font-size: 31px;
}
.story-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.story-settings section {
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 15px;
  background: #f8fafc;
}
.story-segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 4px;
  border-radius: 12px;
  background: #e2e8f0;
}
.story-segmented button {
  border: 0;
  border-radius: 9px;
  padding: 9px 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.story-segmented button.active {
  background: white;
  color: #6d28d9;
  box-shadow: 0 3px 10px rgba(15,23,42,.12);
}
.story-summary {
  padding: 11px 13px;
  border-radius: 13px;
  background: linear-gradient(135deg, #fef2f2, #fff 48%, #eff6ff);
  border: 1px solid #e2e8f0;
  font-size: 12px;
  color: var(--muted);
}
.story-summary strong { color: var(--ink); }
.story-level-title { margin: 16px 0 9px; font-size: 15px; }
.story-levels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.story-level-card {
  position: relative;
  min-height: 116px;
  padding: 10px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: white;
  text-align: left;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.story-level-card:not(:disabled):hover { transform: translateY(-2px); }
.story-level-card.selected {
  border-color: #8b5cf6;
  box-shadow: 0 8px 20px rgba(124,58,237,.16);
  background: #faf5ff;
}
.story-level-card:disabled { opacity: .52; cursor: not-allowed; }
.story-level-card b { display: block; font-size: 11px; color: #7c3aed; }
.story-level-card strong { display: block; margin-top: 5px; font-size: 12px; }
.story-level-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.35; }
.story-level-card .level-icon { font-size: 24px; }
.story-level-card .lock { position: absolute; right: 8px; top: 7px; font-size: 13px; }
.story-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}
.story-actions .text-btn { margin: 0; }
.story-actions .primary { min-width: 190px; }
.story-objective-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 8px;
  font-weight: 800;
  color: #475569;
}
.order-card .queue-badge {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  margin-right: 4px;
  border-radius: 99px;
  background: #e2e8f0;
  color: #334155;
  font-size: 9px;
  font-weight: 900;
  vertical-align: middle;
}

@media (max-width: 820px) {
  .story-settings { grid-template-columns: 1fr; }
  .story-levels { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .story-levels { grid-template-columns: 1fr; }
  .story-actions { flex-direction: column-reverse; align-items: stretch; }
  .story-actions .primary { width: 100%; }
}
