/* =========================================================
   Paper Command — global styles
   ========================================================= */
:root {
  --paper:        #f8f5e8;
  --paper-graph:  #f4f9f0;
  --paper-dotted: #fbf8ee;
  --ink:          #2a2a2a;
  --ink-soft:     #555;
  --player:       #3a8a52;
  --player-tint:  #d3ebd9;
  --enemy:        #cc3333;
  --enemy-tint:   #ffd0d0;
  --gold:         #d99500;
  --bomb:         #e8772a;
  --warn-tint:    #fff2c2;
  --hq-fill:      #ffffff;
  --factory-fill: #fff5d6;
  --airfield-fill:#dceaf8;
  --shadow:       0 6px 0 rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Comic Sans MS', 'Marker Felt', 'Patrick Hand', cursive;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

/* Canvas always present, but hidden behind menus */
#gameCanvas { display: block; cursor: crosshair; }

/* Visibility states driven by body class */
body.in-menu #ui                 { display: none; }
body.in-menu #gameCanvas         { filter: blur(2px) opacity(0.45); }
body.in-game .screen             { display: none !important; }
body.in-game #ui                 { display: flex; }

/* =========================================================
   Sound toggle (always visible, top-right)
   ========================================================= */
#soundToggle {
  position: fixed;
  top: 12px; right: 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  padding: 6px 12px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: var(--player-tint);
  color: var(--ink);
  cursor: pointer;
  z-index: 30;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.06s, background 0.1s;
}
#soundToggle:hover { background: #b8e0c2; }
#soundToggle:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#soundToggle.off { background: var(--enemy-tint); }
#soundToggle.off:hover { background: #ffb8b8; }

/* =========================================================
   HUD (game UI bar)
   ========================================================= */
#ui {
  position: fixed; bottom: 0; left: 0; right: 0; height: 92px;
  background: var(--paper);
  border-top: 3px solid var(--ink);
  padding: 6px 10px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  overflow-x: auto;
  z-index: 5;
}
#ui .credits {
  font-size: 18px; font-weight: bold;
  background: var(--warn-tint);
  border: 2.5px solid var(--ink);
  padding: 6px 12px;
  border-radius: 14px;
  min-width: 100px; text-align: center;
  align-self: center;
  box-shadow: 0 2px 0 var(--ink);
}
#levelLabel {
  font-weight: bold; padding: 6px 12px;
  border: 2.5px solid var(--ink); border-radius: 12px;
  background: var(--player-tint);
  align-self: center;
  box-shadow: 0 2px 0 var(--ink);
}
#buildBar {
  display: flex; gap: 8px; flex-wrap: nowrap; align-items: stretch;
}
.build-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  padding: 4px 6px 4px;
  background: #fffdf4;
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 2px 0 var(--ink);
}
.build-hint {
  align-self: center;
  padding: 8px 16px;
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  border: 1.5px dashed #aaa;
  border-radius: 8px;
  background: #fffdf4;
}
.selected-tag {
  align-self: center;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1.5px;
  padding: 4px 10px;
  background: #fff2c2;
  border: 2px solid var(--gold);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 2px 0 var(--gold);
  text-transform: uppercase;
}
.queue-tag {
  align-self: center;
  font-size: 12px;
  font-weight: bold;
  padding: 4px 10px;
  background: #e0eaf8;
  border: 2px solid var(--ink);
  border-radius: 8px;
}
.build-section > .lbl {
  font-size: 9px; font-weight: bold;
  letter-spacing: 1.5px;
  color: var(--ink-soft);
  margin: 0;
}
.build-section .btns {
  display: flex; gap: 4px;
}
#ui button {
  font-family: inherit;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
  border-radius: 7px;
  transition: transform 0.06s, background 0.1s, box-shadow 0.08s;
}
#ui button:hover:not(:disabled) { background: #f5f0d8; transform: translateY(-1px); }
#ui button:disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.6); }

.icon-btn {
  width: 60px; height: 64px;
  padding: 2px;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  position: relative;
}
.icon-btn canvas {
  display: block;
  width: 50px; height: 36px;
  pointer-events: none;
}
.icon-btn .label {
  font-size: 9px; font-weight: bold;
  line-height: 1;
  letter-spacing: 0.3px;
}
.icon-btn .cost {
  font-size: 10px; font-weight: bold;
  color: var(--gold);
  line-height: 1;
}
.icon-btn.active {
  background: var(--warn-tint) !important;
  box-shadow: inset 0 0 0 2px var(--gold), 0 0 8px rgba(217, 149, 0, 0.4);
  transform: translateY(1px);
}
.text-btn {
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
  align-self: center;
}
.hud-btn {
  margin-left: auto;
  align-self: center;
  font-size: 13px;
  padding: 8px 14px;
  background: var(--player-tint) !important;
  font-weight: bold;
}

/* =========================================================
   Screens (menu overlays)
   ========================================================= */
.screen {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  z-index: 10;
  padding: 16px;
}
.screen.active { display: flex; }

.paper {
  position: relative;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 44px;
  min-width: 360px;
  max-width: 92vw;
  text-align: center;
  transform: rotate(-0.5deg);
  background-image:
    repeating-linear-gradient(to bottom,
      transparent 0 26px,
      rgba(110, 150, 200, 0.18) 26px 27px);
  background-attachment: local;
}
.paper.wide { min-width: min(960px, 95vw); }
.paper::before {
  content: "";
  position: absolute; left: 38px; top: 0; bottom: 0;
  width: 2px; background: rgba(220, 80, 80, 0.45);
  border-radius: 2px;
}

/* Title screen */
.game-title {
  font-size: 64px;
  line-height: 0.95;
  margin: 8px 0 0;
  letter-spacing: 2px;
  color: var(--player);
  text-shadow:
    3px 3px 0 var(--ink),
    -1px -1px 0 var(--paper);
  transform: rotate(-1.5deg);
}
.game-title span { color: var(--enemy); }
.tagline {
  font-size: 18px; color: var(--ink-soft);
  margin: 12px 0 28px;
  font-style: italic;
}

.menu-buttons {
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; margin-top: 8px;
}
.btn-big {
  font-family: inherit;
  font-size: 22px;
  padding: 12px 36px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  cursor: pointer;
  min-width: 240px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.1s;
}
.btn-big:hover { background: var(--warn-tint); }
.btn-big:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn-big.primary { background: var(--player-tint); }
.btn-big.primary:hover { background: #b8e0c2; }
.btn-big.danger { background: var(--enemy-tint); }
.btn-big.danger:hover { background: #ffb8b8; }

.footer-hint {
  margin-top: 26px;
  font-size: 12px;
  color: var(--ink-soft);
  opacity: 0.7;
}

/* Doodle decoration corners (CSS-only sketches) */
.doodle {
  position: absolute;
  width: 70px; height: 70px;
  pointer-events: none;
  opacity: 0.85;
}
.doodle.d1 {
  top: -28px; left: 24px;
  background: radial-gradient(circle at 50% 60%, transparent 12px, var(--ink) 12px 14px, transparent 14px),
              radial-gradient(circle at 30% 40%, transparent 4px, var(--ink) 4px 6px, transparent 6px),
              radial-gradient(circle at 70% 40%, transparent 4px, var(--ink) 4px 6px, transparent 6px);
  transform: rotate(-12deg);
}
.doodle.d2 {
  top: -18px; right: 18px;
  background:
    linear-gradient(var(--ink), var(--ink)) no-repeat 50% 0/3px 30px,
    radial-gradient(circle at 50% 50%, var(--enemy-tint) 14px, var(--ink) 14px 16px, transparent 16px);
  transform: rotate(8deg);
}
.doodle.d3 {
  bottom: -28px; right: 30px;
  background:
    linear-gradient(var(--ink), var(--ink)) no-repeat 0 50%/100% 3px,
    radial-gradient(circle at 50% 50%, var(--player-tint) 12px, var(--ink) 12px 14px, transparent 14px);
  transform: rotate(20deg);
}

/* Sub-headers */
.paper h2 {
  font-size: 36px;
  margin: 0 0 6px;
  color: var(--ink);
  letter-spacing: 1px;
}
.paper .sub {
  color: var(--ink-soft);
  margin: 0 0 24px;
  font-style: italic;
}

/* Back button */
.btn-back {
  font-family: inherit;
  font-size: 16px;
  padding: 8px 18px;
  border: 2px solid var(--ink);
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 20px;
}
.btn-back:hover { background: var(--warn-tint); }

/* =========================================================
   Cards
   ========================================================= */
.cards {
  display: flex; gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0 8px;
}
.card {
  position: relative;
  width: 240px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 18px 16px;
  text-align: left;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
  transform: rotate(-1deg);
}
.card:nth-child(2) { transform: rotate(0.5deg); }
.card:nth-child(3) { transform: rotate(-1.5deg); }
.card:hover {
  transform: translateY(-6px) rotate(0deg);
  box-shadow: 0 11px 0 var(--ink);
}
.card-stripe {
  position: absolute; top: 0; left: 0; right: 0;
  height: 14px;
  border-bottom: 2px solid var(--ink);
  border-radius: 11px 11px 0 0;
}
.card-cadet   .card-stripe { background: var(--player-tint); }
.card-officer .card-stripe { background: var(--warn-tint); }
.card-general .card-stripe { background: var(--enemy-tint); }
.card h3 {
  margin: 14px 0 8px;
  font-size: 28px;
  letter-spacing: 1px;
  text-align: center;
}
.card-cadet h3   { color: var(--player); }
.card-officer h3 { color: var(--gold); }
.card-general h3 { color: var(--enemy); }
.card-desc {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--ink-soft);
  font-style: italic;
  min-height: 42px;
}
.card-stats {
  margin: 0 0 16px;
  padding: 8px 12px;
  list-style: none;
  background: var(--paper);
  border: 1.5px dashed #aaa;
  border-radius: 8px;
  font-size: 14px;
}
.card-stats li { margin: 3px 0; }
.card-stats b { color: var(--ink); }
.card-btn {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 10px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-weight: bold;
}
.card-cadet   .card-btn { background: var(--player-tint); }
.card-officer .card-btn { background: var(--warn-tint); }
.card-general .card-btn { background: var(--enemy-tint); }
.card-btn:hover { filter: brightness(0.95); }

/* =========================================================
   Generals (faction selection cards)
   ========================================================= */
.generals {
  display: flex; gap: 22px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0 8px;
}
.general-card {
  position: relative;
  width: 240px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 0 16px 18px;
  text-align: left;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
  transform: rotate(-1deg);
  overflow: hidden;
}
.general-card:nth-child(2) { transform: rotate(0.5deg); }
.general-card:nth-child(3) { transform: rotate(-1.5deg); }
.general-card:hover {
  transform: translateY(-6px) rotate(0deg);
  box-shadow: 0 11px 0 var(--ink);
}
.general-flag {
  height: 88px;
  margin: 0 -16px 12px;
  border-bottom: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.general-flag canvas { display: block; }
.general-card.general-usa     .general-flag { background: #1d4f8c; }
.general-card.general-russia  .general-flag { background: #a02020; }
.general-card.general-china   .general-flag { background: #cc1818; }
.general-card h3 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: 1px;
  text-align: center;
}
.general-card.general-usa     h3 { color: #1d4f8c; }
.general-card.general-russia  h3 { color: #a02020; }
.general-card.general-china   h3 { color: #cc1818; }
.general-motto {
  margin: 0 0 10px;
  text-align: center;
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
}
.general-desc {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--ink);
  min-height: 56px;
  line-height: 1.3;
}
.general-btn {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 10px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-weight: bold;
}
.general-card.general-usa     .general-btn { background: #cfdaf0; }
.general-card.general-russia  .general-btn { background: #f0d6d6; }
.general-card.general-china   .general-btn { background: #ffd6c8; }
.general-btn:hover { filter: brightness(0.95); }

/* =========================================================
   How-to list
   ========================================================= */
.howto {
  text-align: left;
  max-width: 540px;
  margin: 0 auto;
  font-size: 16px;
}
.howto dt {
  font-weight: bold;
  color: var(--player);
  margin-top: 12px;
}
.howto dd {
  margin: 2px 0 8px 16px;
}

/* =========================================================
   Banner (win/lose during game)
   ========================================================= */
#banner {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 24px;
  padding: 24px 48px;
  text-align: center;
  z-index: 20;
  box-shadow: var(--shadow);
  transition: transform 0.4s cubic-bezier(0.34, 1.5, 0.64, 1);
}
#banner.show { transform: translate(-50%, -50%) scale(1); }
#bannerText {
  font-size: 40px;
  font-weight: bold;
  color: var(--player);
  margin-bottom: 16px;
}
#banner.lose #bannerText { color: var(--enemy); }
.banner-buttons {
  display: flex; gap: 12px; justify-content: center;
}
.banner-buttons button {
  font-family: inherit;
  font-size: 16px;
  padding: 8px 18px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
#bannerBtn { background: var(--player-tint); }
.banner-buttons button:hover { filter: brightness(0.95); }
