
:root {
  --gold: #e8bd61;
  --gold-dark: #8f6227;
  --ink: #07111d;
  --panel: rgba(8, 18, 28, 0.92);
  --cream: #f4ead1;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050b12;
  color: white;
  font-family: Inter, system-ui, sans-serif;
}

button { font: inherit; }

#game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  isolation: isolate;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #86d7f1;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
}

.screen.active { display: block; }

#main-menu {
  background:
    radial-gradient(circle at 72% 32%, rgba(232, 162, 71, 0.16), transparent 24%),
    linear-gradient(90deg, rgba(3, 10, 17, 0.78) 0%, rgba(3, 10, 17, 0.48) 42%, rgba(3, 10, 17, 0.05) 72%);
}

.menu-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 160px 55px rgba(0,0,0,.48);
}

.title-wrap {
  position: absolute;
  left: clamp(40px, 8vw, 130px);
  top: clamp(55px, 11vh, 120px);
  text-shadow: 0 6px 25px rgba(0,0,0,.8);
}

.eyebrow {
  color: var(--gold);
  font-size: clamp(10px, 1vw, 14px);
  letter-spacing: .28em;
  font-weight: 800;
  margin: 0 0 12px;
}

h1 {
  font-family: Cinzel, serif;
  font-size: clamp(58px, 8vw, 126px);
  line-height: .76;
  letter-spacing: -.045em;
  margin: 0;
  color: #fff8df;
}

h1 span {
  color: var(--gold);
  letter-spacing: .03em;
}

.tagline {
  margin: 24px 0 0;
  font-family: Cinzel, serif;
  font-size: clamp(14px, 1.5vw, 22px);
  color: #e8edf0;
}

.menu-panel {
  position: absolute;
  left: clamp(40px, 8vw, 130px);
  bottom: clamp(55px, 9vh, 100px);
  width: min(330px, 76vw);
  display: grid;
  gap: 10px;
}

.menu-button {
  position: relative;
  width: 100%;
  min-height: 52px;
  padding: 0 24px;
  border: 1px solid rgba(226, 190, 113, .32);
  background: linear-gradient(90deg, rgba(7,17,29,.94), rgba(13,26,38,.82));
  color: #e9edf1;
  text-transform: uppercase;
  letter-spacing: .17em;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  text-align: left;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
  clip-path: polygon(0 0, 96% 0, 100% 50%, 96% 100%, 0 100%, 4% 50%);
}

.menu-button::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 50%;
  width: 4px;
  height: 4px;
  transform: translateY(-50%) rotate(45deg);
  background: var(--gold);
  opacity: .5;
}

.menu-button:hover:not(:disabled) {
  transform: translateX(8px);
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(34,27,19,.96), rgba(20,27,34,.88));
}

.menu-button.primary {
  color: #171109;
  background: linear-gradient(90deg, #dba64a, #f3d487);
  border-color: #ffe4a5;
}

.menu-button:disabled {
  opacity: .32;
  cursor: not-allowed;
}

.menu-footer {
  position: absolute;
  right: 22px;
  bottom: 14px;
  margin: 0;
  color: rgba(255,255,255,.45);
  font-size: 11px;
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.hidden { display: none !important; }

.hud-panel, .day-panel, .build-panel {
  pointer-events: auto;
  background: linear-gradient(180deg, rgba(46,31,18,.96), rgba(23,17,13,.96));
  border: 3px solid #1b120c;
  outline: 2px solid #8c6533;
  box-shadow: 0 10px 24px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,218,145,.16);
}

.resource-panel {
  position: absolute;
  left: 26px;
  bottom: 24px;
  min-width: 235px;
  padding: 14px 20px;
  display: grid;
  gap: 8px;
}

.resource-panel div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  font-weight: 900;
  text-shadow: 0 2px 2px rgba(0,0,0,.5);
}

.heart { color: #ff5656; font-size: 24px; }
.coin { color: #ffd35a; font-size: 28px; }
.wave { color: #e9e4d6; font-size: 21px; }

.day-panel {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 52vw);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.time-track {
  height: 9px;
  border: 1px solid rgba(255,255,255,.26);
  background: #0a1015;
  overflow: hidden;
}

#time-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f1c66a, #f17f4a, #6960a8);
}

.build-panel {
  position: absolute;
  right: 24px;
  bottom: 24px;
  padding: 9px;
  display: flex;
  gap: 8px;
}

.build-card {
  width: 88px;
  min-height: 92px;
  border: 1px solid #6f5030;
  background: linear-gradient(#d8c59c, #b69a6e);
  color: #251b12;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  cursor: pointer;
  font-weight: 800;
  transition: transform .15s ease, filter .15s ease;
}

.build-card:hover { transform: translateY(-5px); filter: brightness(1.08); }
.build-card.selected { outline: 3px solid #fff0a8; transform: translateY(-7px); }
.build-icon { font-size: 30px; line-height: 1; }
.build-card small { font-size: 12px; }

.pause-button {
  position: absolute;
  z-index: 7;
  top: 20px;
  right: 24px;
  width: 45px;
  height: 45px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(7,17,29,.74);
  color: white;
  cursor: pointer;
}

.dialog {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(1,6,10,.68);
  backdrop-filter: blur(5px);
}

.dialog-card, .pause-card {
  position: relative;
  width: min(560px, 88vw);
  padding: 34px;
  border: 1px solid #b98c45;
  background: linear-gradient(180deg, #162534, #09131d);
  box-shadow: 0 30px 80px rgba(0,0,0,.65);
}

.dialog-card h2, .pause-card h2 {
  margin: 0 0 20px;
  font: 700 36px Cinzel, serif;
  color: var(--gold);
}

.dialog-card p, .dialog-card li {
  color: #dbe2e7;
  line-height: 1.65;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: white;
  font-size: 30px;
  cursor: pointer;
}

.pause-screen {
  z-index: 20;
  background: rgba(1,6,10,.7);
  backdrop-filter: blur(7px);
}

.pause-screen.active {
  display: grid;
  place-items: center;
}

.pause-card {
  text-align: center;
}

.pause-card .menu-button {
  margin-top: 10px;
  text-align: center;
}

.transition {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: #02070c;
  transform: translateX(-101%);
}

.transition.play {
  animation: screenWipe 1.15s cubic-bezier(.76,0,.24,1);
}

@keyframes screenWipe {
  0% { transform: translateX(-101%); }
  45%, 55% { transform: translateX(0); }
  100% { transform: translateX(101%); }
}

@media (max-width: 760px) {
  .title-wrap { top: 42px; }
  .menu-panel { bottom: 38px; }
  .build-panel { right: 10px; bottom: 10px; transform: scale(.82); transform-origin: bottom right; }
  .resource-panel { left: 10px; bottom: 10px; transform: scale(.86); transform-origin: bottom left; }
}


.world-intro {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -12px);
  min-width: min(520px, 84vw);
  padding: 18px 28px;
  border: 1px solid rgba(244, 214, 145, .58);
  background: linear-gradient(180deg, rgba(8,18,28,.92), rgba(5,12,19,.82));
  box-shadow: 0 18px 45px rgba(0,0,0,.4);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease, transform .5s ease;
}

.world-intro.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.world-intro h2 {
  margin: 0 0 6px;
  color: var(--gold);
  font: 700 clamp(22px, 3vw, 34px) Cinzel, serif;
}

.world-intro p {
  margin: 0;
  color: #edf0e7;
  font-size: 13px;
  letter-spacing: .04em;
}


.castle-panel {
  position: absolute;
  z-index: 6;
  top: 78px;
  left: 24px;
  width: min(320px, calc(100vw - 48px));
  padding: 16px;
  border: 3px solid #1b120c;
  outline: 2px solid #8c6533;
  color: #f1e7d2;
  background: linear-gradient(180deg, rgba(48,32,18,.97), rgba(19,14,11,.97));
  box-shadow: 0 12px 30px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,218,145,.12);
  pointer-events: auto;
}

.castle-level-row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
}

.panel-kicker {
  display: block;
  color: #d9b15e;
  font-size: 9px;
  letter-spacing: .18em;
  font-weight: 900;
  margin-bottom: 3px;
}

#castle-level {
  display: block;
  font: 700 16px Cinzel, serif;
}

#castle-health-label {
  color: #ffcf79;
  font-size: 12px;
  font-weight: 800;
}

.castle-progress {
  height: 8px;
  margin: 13px 0 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.24);
  background: #080b0d;
}

#castle-progress-fill {
  width: 5%;
  height: 100%;
  background: linear-gradient(90deg, #a36e2e, #f1c665);
  transition: width .35s ease;
}

.castle-stats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #cfc8b9;
  font-size: 11px;
}

.castle-stats strong { color: white; }

.upgrade-castle-button {
  width: 100%;
  margin-top: 13px;
  min-height: 54px;
  border: 1px solid #f1d58d;
  color: #22170c;
  background: linear-gradient(180deg, #f2d17e, #c78c37);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55);
  transition: transform .16s ease, filter .16s ease;
}

.upgrade-castle-button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.upgrade-castle-button span {
  display: grid;
  text-align: left;
}

.upgrade-castle-button small {
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 900;
}

.upgrade-castle-button strong {
  font-size: 14px;
  margin-top: 2px;
}

.upgrade-castle-button b {
  font-size: 24px;
}

.upgrade-castle-button:disabled {
  cursor: not-allowed;
  filter: grayscale(.75);
  opacity: .55;
}

#castle-upgrade-note {
  margin: 10px 0 0;
  color: #bdb5a6;
  font-size: 10px;
  line-height: 1.45;
}

.upgrade-toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 12%;
  transform: translate(-50%, -12px);
  min-width: 310px;
  padding: 16px 22px;
  text-align: center;
  color: #fff4cf;
  border: 1px solid #e5bd65;
  background: rgba(15, 19, 20, .94);
  box-shadow: 0 18px 45px rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}

.upgrade-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .castle-panel {
    top: 70px;
    left: 10px;
    transform: scale(.82);
    transform-origin: top left;
  }
}


/* Compact castle panel — v0.4 */
.castle-panel {
  top: 72px;
  left: 18px;
  width: 242px;
  padding: 11px 12px 10px;
  border: 1px solid rgba(226, 190, 113, .58);
  outline: 1px solid rgba(28, 18, 10, .95);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(42,29,18,.96), rgba(15,12,10,.96));
  box-shadow:
    0 10px 24px rgba(0,0,0,.34),
    inset 0 1px 0 rgba(255,235,188,.12);
}

.castle-level-row {
  align-items: center;
}

.panel-kicker {
  margin-bottom: 1px;
  font-size: 7px;
  letter-spacing: .16em;
  opacity: .86;
}

#castle-level {
  font-size: 13px;
  letter-spacing: .01em;
}

#castle-health-label {
  padding: 3px 6px;
  border: 1px solid rgba(255,207,121,.28);
  border-radius: 5px;
  background: rgba(0,0,0,.18);
  font-size: 10px;
}

.castle-progress {
  height: 5px;
  margin: 9px 0 7px;
  border-radius: 99px;
}

#castle-progress-fill {
  border-radius: inherit;
}

.castle-stats {
  font-size: 9px;
  color: #bdb5a6;
}

.upgrade-castle-button {
  min-height: 40px;
  margin-top: 9px;
  padding: 6px 10px;
  border-radius: 6px;
}

.upgrade-castle-button small {
  font-size: 8px;
}

.upgrade-castle-button strong {
  margin-top: 1px;
  font-size: 11px;
}

.upgrade-castle-button b {
  font-size: 17px;
}

#castle-upgrade-note {
  display: none;
}

/* Extensible developer menu */
.mod-menu {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 7, 12, .76);
  backdrop-filter: blur(8px);
}

.mod-menu-card {
  width: min(760px, 94vw);
  max-height: 88vh;
  overflow: hidden;
  border: 1px solid #b88c45;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(18,31,42,.99), rgba(7,15,23,.99));
  box-shadow: 0 30px 90px rgba(0,0,0,.7);
}

.mod-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(232,189,97,.24);
  background: linear-gradient(90deg, rgba(232,189,97,.08), transparent);
}

.mod-kicker {
  color: var(--gold);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .22em;
}

.mod-menu-header h2 {
  margin: 3px 0 0;
  color: #fff3d4;
  font: 700 27px Cinzel, serif;
}

.mod-close {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.17);
  border-radius: 7px;
  background: rgba(255,255,255,.04);
  color: #fff;
  font-size: 25px;
  cursor: pointer;
}

.mod-menu-content {
  max-height: calc(88vh - 130px);
  overflow-y: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mod-section {
  padding: 14px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 9px;
  background: rgba(255,255,255,.035);
}

.mod-section h3 {
  margin: 0 0 12px;
  color: var(--gold);
  font: 700 14px Cinzel, serif;
}

.mod-control-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}

.mod-control-row strong {
  min-width: 72px;
  text-align: center;
  color: #fff1c6;
}

.mod-menu button {
  min-height: 36px;
  border: 1px solid rgba(232,189,97,.28);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(37,52,64,.95), rgba(20,31,40,.95));
  color: #e9eef1;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}

.mod-menu button:hover {
  transform: translateY(-1px);
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(68,62,43,.95), rgba(31,37,40,.95));
}

.mod-button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.mod-button-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mod-button-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#mod-castle-slider {
  width: 100%;
  margin: 2px 0 12px;
  accent-color: var(--gold);
}

.mod-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  color: #dce3e7;
  font-size: 11px;
}

.mod-menu-footer {
  padding: 11px 18px;
  border-top: 1px solid rgba(232,189,97,.16);
  color: #9fa9af;
  font-size: 10px;
  text-align: center;
}

.mod-menu-footer strong {
  color: #efd18b;
}

@media (max-width: 680px) {
  .mod-menu-content {
    grid-template-columns: 1fr;
  }

  .mod-button-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .castle-panel {
    transform: scale(.88);
    transform-origin: top left;
  }
}


/* Castle panel polish — v0.5 */
.castle-panel {
  width: 226px;
  padding: 10px 11px 9px;
  border-color: rgba(239, 202, 123, .64);
  background:
    radial-gradient(circle at 18% 0%, rgba(239,202,123,.10), transparent 38%),
    linear-gradient(180deg, rgba(38,27,18,.97), rgba(13,11,9,.97));
}

.upgrade-castle-button {
  background:
    linear-gradient(180deg, #f4d68b 0%, #d39b43 58%, #b87727 100%);
  border-color: #f8e4ae;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.58),
    0 4px 10px rgba(0,0,0,.22);
}

.upgrade-castle-button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.1);
}


.camera-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  min-width: 260px;
  padding: 8px 12px;
  border: 1px solid rgba(231,194,112,.42);
  border-radius: 7px;
  background: rgba(7,15,22,.78);
  color: rgba(255,255,255,.8);
  text-align: center;
  font-size: 10px;
  letter-spacing: .06em;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.camera-hint > span {
  color: #f0c96f;
  font-weight: 900;
}

.camera-track {
  height: 4px;
  margin-top: 6px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(255,255,255,.13);
}

#camera-position {
  width: 18%;
  height: 100%;
  border-radius: inherit;
  background: #e7bd61;
  transform: translateX(0%);
}

.camera-hint { display: none !important; }


/* =========================================================
   DAY SYSTEM & TIME SPEED CONTROLS
   ========================================================= */

.time-controls {
  position: absolute;
  top: 22px;
  right: 86px;
  z-index: 7;
}

.time-speed-button {
  min-width: 92px;
  min-height: 50px;
  padding: 7px 15px;
  border: 1px solid rgba(232, 189, 97, .72);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(24, 31, 37, .96), rgba(8, 15, 22, .96));
  color: #f4ead1;
  box-shadow: 0 8px 22px rgba(0,0,0,.3), inset 0 1px rgba(255,255,255,.08);
  cursor: pointer;
  text-transform: uppercase;
}

.time-speed-button span {
  display: block;
  color: #d9c8a1;
  font-size: 9px;
  letter-spacing: .16em;
  font-weight: 800;
}

.time-speed-button strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-family: Cinzel, serif;
  font-size: 18px;
}

.time-speed-button:hover {
  border-color: #f3cd78;
  transform: translateY(-1px);
}

.next-day-panel {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 14;
  transform: translate(-50%, -50%);
  width: min(390px, calc(100vw - 34px));
  padding: 20px;
  border: 1px solid rgba(232, 189, 97, .72);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(28, 34, 39, .98), rgba(7, 14, 21, .98));
  box-shadow: 0 18px 55px rgba(0,0,0,.55), inset 0 1px rgba(255,255,255,.08);
  text-align: center;
}

.next-day-panel p {
  margin: 0 0 12px;
  color: #d8ccb3;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: 11px;
  font-weight: 800;
}

.next-day-panel button {
  width: 100%;
  min-height: 58px;
  border: 1px solid #f1cf80;
  border-radius: 9px;
  background: linear-gradient(180deg, #e7be65, #a86a20);
  color: #16120c;
  font-family: Cinzel, serif;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 1px rgba(255,255,255,.45), 0 8px 20px rgba(0,0,0,.28);
}

.next-day-panel button:hover {
  filter: brightness(1.08);
}

@media (max-width: 760px) {
  .time-controls {
    top: 78px;
    right: 14px;
  }

  .time-speed-button {
    min-width: 74px;
    min-height: 44px;
  }
}


/* =========================================================
   V2 HUD & DEFENCE WORKSHOP
   ========================================================= */

.time-controls {
  pointer-events: auto;
}

.resource-panel {
  left: 22px;
  bottom: 22px;
  width: 270px;
  min-width: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
  border: 1px solid rgba(228, 190, 110, .72);
  outline: 1px solid rgba(65, 42, 23, .95);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(37, 43, 46, .98), rgba(15, 22, 27, .98));
  box-shadow:
    0 14px 34px rgba(0,0,0,.42),
    inset 0 1px rgba(255,255,255,.08),
    inset 0 0 28px rgba(235,187,91,.04);
}

.resource-panel-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 15px;
  border-bottom: 1px solid rgba(224,184,102,.28);
  background:
    linear-gradient(90deg, rgba(120,77,29,.38), rgba(34,39,42,.15));
}

.resource-crown {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(239,202,124,.42);
  border-radius: 8px;
  color: #efcb7d;
  background: rgba(4,10,14,.30);
  font-size: 23px;
}

.resource-panel-header small,
.build-panel-header small {
  display: block;
  color: #af9b78;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.resource-panel-header strong,
.build-panel-header strong {
  display: block;
  margin-top: 2px;
  color: #f1e7d1;
  font-family: Cinzel, serif;
  font-size: 14px;
  letter-spacing: .03em;
}

.resource-row {
  display: grid !important;
  grid-template-columns: 37px 1fr;
  align-items: center;
  gap: 10px !important;
  min-height: 55px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.055);
}

.resource-row:last-child {
  border-bottom: 0;
}

.resource-icon {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 8px;
  background: rgba(2,8,12,.35);
  box-shadow: inset 0 1px rgba(255,255,255,.06);
}

.resource-copy span {
  display: block;
  color: #aeb7b7;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.resource-copy strong {
  display: block;
  margin-top: 2px;
  color: #fff7e8;
  font-family: Cinzel, serif;
  font-size: 16px;
}

.resource-copy b {
  font-weight: 800;
}

.resource-health-track {
  height: 7px;
  margin: -5px 14px 8px 61px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 20px;
  overflow: hidden;
  background: #081014;
}

#resource-health-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7d1e25, #e34d49, #f58b65);
  box-shadow: 0 0 10px rgba(235,76,66,.25);
  transition: width .25s ease;
}

.build-panel {
  right: 20px;
  bottom: 20px;
  width: 354px;
  padding: 0;
  display: block;
  overflow: hidden;
  border: 1px solid rgba(228, 190, 110, .72);
  outline: 1px solid rgba(65, 42, 23, .95);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(37, 43, 46, .98), rgba(15, 22, 27, .98));
  box-shadow:
    0 14px 34px rgba(0,0,0,.42),
    inset 0 1px rgba(255,255,255,.08);
}

.build-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(224,184,102,.28);
  background:
    linear-gradient(90deg, rgba(120,77,29,.38), rgba(34,39,42,.15));
}

#build-unlock-status {
  min-width: 48px;
  padding: 5px 8px;
  border: 1px solid rgba(235,199,119,.30);
  border-radius: 20px;
  color: #efcb7d;
  background: rgba(4,10,14,.32);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.build-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  max-height: 287px;
  padding: 10px;
  overflow-y: auto;
}

.build-card {
  position: relative;
  width: auto;
  min-height: 76px;
  padding: 9px;
  border: 1px solid rgba(202,167,95,.30);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(72,77,75,.98), rgba(29,37,41,.98));
  color: #f4ead8;
  display: grid;
  grid-template-columns: 36px 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: stretch;
  gap: 2px 9px;
  text-align: left;
  box-shadow:
    inset 0 1px rgba(255,255,255,.08),
    0 5px 13px rgba(0,0,0,.18);
}

.build-card:hover:not(.locked) {
  transform: translateY(-2px);
  border-color: rgba(239,201,119,.72);
  filter: brightness(1.08);
}

.build-card.selected {
  border-color: #f1ce7b;
  box-shadow:
    inset 0 0 0 1px rgba(241,206,123,.40),
    0 0 18px rgba(225,171,69,.18);
}

.build-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 36px;
  height: 46px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 7px;
  color: #efcb7d;
  background: rgba(2,8,12,.34);
  font-size: 23px;
}

.build-copy {
  min-width: 0;
}

.build-copy strong {
  display: block;
  color: #fff5e3;
  font-family: Cinzel, serif;
  font-size: 12px;
}

.build-copy small {
  display: block;
  margin-top: 2px;
  color: #aeb7b7;
  font-size: 9px;
}

.build-cost {
  color: #eec76f;
  font-size: 10px;
  font-weight: 900;
}

.build-lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  color: #c9bba1;
  background: rgba(6,11,15,.82);
  backdrop-filter: blur(1.5px);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.build-card.locked {
  cursor: not-allowed;
  filter: saturate(.45);
}

.build-panel-note {
  margin: 0;
  padding: 0 12px 11px;
  color: #8e999a;
  font-size: 9px;
  line-height: 1.4;
  text-align: center;
}

@media (max-width: 960px) {
  .resource-panel {
    width: 232px;
  }

  .build-panel {
    width: 306px;
  }

  .build-grid {
    grid-template-columns: 1fr;
    max-height: 245px;
  }
}


/* =========================================================
   V2.1 EXPANDING DEFENCE WORKSHOP
   ========================================================= */

.build-grid {
  max-height: none;
  overflow: visible;
  align-items: start;
}

.build-panel {
  height: auto;
}

.build-hidden {
  display: none !important;
}


/* =========================================================
   V2.6 SMARTER DEFENCE WORKSHOP
   ========================================================= */

.build-panel {
  width: 430px;
  max-width: min(430px, calc(100vw - 42px));
}

.build-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  max-height: none;
  padding: 10px 10px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  align-items: stretch;
}

.build-grid::-webkit-scrollbar {
  height: 8px;
}

.build-grid::-webkit-scrollbar-thumb {
  background: rgba(227, 189, 108, .28);
  border-radius: 999px;
}

.build-card {
  flex: 0 0 148px;
  min-height: 84px;
  scroll-snap-align: start;
}

.build-panel-note {
  padding-bottom: 9px;
}

@media (max-width: 960px) {
  .build-panel {
    width: min(360px, calc(100vw - 26px));
    right: 12px;
    bottom: 12px;
  }

  .build-card {
    flex-basis: 136px;
    min-height: 82px;
  }

  .build-grid {
    grid-template-columns: none;
  }
}


/* =========================================================
   V2.7 EXPANDING WORKSHOP WIDTH
   ========================================================= */

.build-panel {
  --build-panel-width: 430px;
  width: var(--build-panel-width);
  max-width: calc(100vw - 42px);
  overflow: hidden;
}

.build-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  max-height: none;
  padding: 10px 10px 8px;
  overflow: hidden;
  align-items: stretch;
}

.build-card {
  flex: 0 0 148px;
  min-height: 84px;
}

@media (max-width: 960px) {
  .build-panel {
    max-width: calc(100vw - 26px);
    right: 12px;
    bottom: 12px;
  }

  .build-grid {
    gap: 6px;
    padding: 9px 9px 7px;
  }

  .build-card {
    flex-basis: 132px;
    min-height: 80px;
  }
}


/* =========================================================
   DAILY SPECIAL ATTACK
   ========================================================= */

.time-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.special-attack-button {
  min-width: 126px;
  min-height: 50px;
  padding: 7px 15px;
  border: 1px solid rgba(255, 119, 92, .82);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(75, 25, 26, .97), rgba(31, 8, 12, .97));
  color: #fff1df;
  box-shadow: 0 8px 22px rgba(0,0,0,.3), inset 0 1px rgba(255,255,255,.08);
  cursor: pointer;
  text-transform: uppercase;
  pointer-events: auto;
}

.special-attack-button span {
  display: block;
  color: #f1b4a6;
  font-size: 9px;
  letter-spacing: .14em;
  font-weight: 800;
}

.special-attack-button strong {
  display: block;
  margin-top: 2px;
  color: #ffd190;
  font-family: Cinzel, serif;
  font-size: 16px;
}

.special-attack-button:hover:not(:disabled) {
  border-color: #ffb18b;
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.special-attack-button:disabled {
  cursor: default;
  opacity: .52;
  filter: grayscale(.35);
}

@media (max-width: 760px) {
  .time-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .special-attack-button {
    min-width: 92px;
    min-height: 44px;
  }
}


/* =========================================================
   V6.0 CRAZYGAMES RESPONSIVE UI
   ========================================================= */

:root {
  --ui-scale: 1;
  --safe-edge: clamp(8px, 1.4vw, 24px);
}

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 360px;
  overflow: hidden;
}

#game-shell {
  position: relative;
  isolation: isolate;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Corner HUD panels scale around their own screen anchor. */
.resource-panel {
  left: var(--safe-edge);
  bottom: var(--safe-edge);
  transform: scale(var(--ui-scale));
  transform-origin: left bottom;
}

.castle-panel {
  left: var(--safe-edge);
  top: var(--safe-edge);
  transform: scale(var(--ui-scale));
  transform-origin: left top;
}

.build-panel {
  right: var(--safe-edge);
  bottom: var(--safe-edge);
  transform: scale(var(--ui-scale));
  transform-origin: right bottom;
  max-width: min(430px, calc((100vw - var(--safe-edge) * 2) / var(--ui-scale)));
}

.time-controls {
  top: var(--safe-edge);
  right: calc(var(--safe-edge) + 58px * var(--ui-scale));
  transform: scale(var(--ui-scale));
  transform-origin: right top;
}

.pause-button {
  top: var(--safe-edge);
  right: var(--safe-edge);
  transform: scale(var(--ui-scale));
  transform-origin: right top;
}

.day-panel {
  top: var(--safe-edge);
  width: min(360px, calc(72vw / var(--ui-scale)));
  transform: translateX(-50%) scale(var(--ui-scale));
  transform-origin: center top;
}

.next-day-panel,
.world-intro,
.dialog-card,
.pause-card,
.mod-menu-card {
  max-width: min(92vw, 760px);
  max-height: 88vh;
}

.title-wrap {
  transform: scale(clamp(.72, var(--ui-scale), 1.08));
  transform-origin: left top;
}

.menu-panel {
  transform: scale(clamp(.72, var(--ui-scale), 1.05));
  transform-origin: left bottom;
}

/* Short landscape embeds: panels become shallower and notes disappear. */
@media (max-height: 700px) {
  .resource-panel {
    padding: 9px 13px;
    gap: 5px;
  }

  .resource-panel-header {
    margin-bottom: 2px;
  }

  .resource-row {
    min-height: 34px;
  }

  .build-panel-note,
  #castle-upgrade-note {
    display: none;
  }

  .build-card {
    min-height: 68px;
  }

  .build-grid {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .menu-panel {
    bottom: 22px;
    gap: 6px;
  }

  .menu-button {
    min-height: 44px;
  }
}

/* Narrow CrazyGames iframe / tablet landscape. */
@media (max-width: 980px) {
  .day-panel {
    width: min(300px, 46vw);
  }

  .build-panel {
    --build-panel-width: 340px;
  }

  .build-card {
    flex-basis: 126px;
  }

  .time-controls {
    gap: 5px;
  }

  .special-attack-button,
  .time-speed-button {
    min-width: 94px;
    min-height: 42px;
    padding: 5px 9px;
  }
}

/* Very small embeds: prevent HUD panels overlapping each other. */
@media (max-width: 720px), (max-height: 520px) {
  .day-panel {
    left: 50%;
    width: min(260px, 44vw);
  }

  .castle-panel {
    max-width: 210px;
  }

  .resource-panel {
    min-width: 190px;
    max-width: 215px;
  }

  .build-panel {
    --build-panel-width: 292px;
  }

  .build-card {
    flex-basis: 112px;
    min-height: 64px;
  }

  .build-copy small,
  .build-panel-note,
  #castle-upgrade-note {
    display: none;
  }

  .time-controls {
    flex-direction: row;
  }

  .special-attack-button,
  .time-speed-button {
    min-width: 78px;
  }
}

/* Large and ultrawide screens: allow a modest increase, never giant UI. */
@media (min-width: 2100px) and (min-height: 1100px) {
  :root {
    --safe-edge: 30px;
  }

  .build-panel {
    --build-panel-width: 470px;
  }

  .build-card {
    flex-basis: 158px;
  }
}


/* =========================================================
   V6.1 RESPONSIVE EXPANDING DEFENCE WORKSHOP
   ========================================================= */

.build-panel {
  --build-panel-width: 354px;
  --build-card-width: 148px;
  --build-columns: 2;

  width: var(--build-panel-width) !important;
  max-width: none !important;
  overflow: visible;
  transition:
    width .28s cubic-bezier(.2, .82, .25, 1),
    filter .28s ease,
    box-shadow .28s ease;
  will-change: width;
}

.build-panel.workshop-resizing {
  filter: brightness(1.06);
  box-shadow:
    0 18px 42px rgba(0,0,0,.44),
    0 0 24px rgba(222,184,100,.14);
}

.build-grid {
  display: grid !important;
  grid-template-columns: repeat(var(--build-columns), var(--build-card-width)) !important;
  grid-auto-flow: column;
  grid-template-rows: 1fr;
  justify-content: end;
  gap: 8px;
  overflow: visible !important;
  max-height: none !important;
}

.build-panel[data-rows="2"] .build-grid {
  grid-template-rows: repeat(2, minmax(64px, auto));
  grid-auto-flow: column;
  align-items: stretch;
  row-gap: 7px;
}

.build-card {
  position: relative;
  width: var(--build-card-width);
  min-width: 0;
  max-width: none;
  flex: none !important;
  transform-origin: center;
}

.build-hidden {
  display: none !important;
}

.build-unlock-pop {
  animation: buildUnlockPop .52s cubic-bezier(.18, .88, .25, 1.22);
  z-index: 4;
}

.build-new-badge {
  position: absolute;
  top: -9px;
  right: -7px;
  z-index: 6;
  padding: 3px 7px;
  border: 1px solid rgba(255,231,154,.92);
  border-radius: 999px;
  background: linear-gradient(180deg, #e9bd58, #8f5c18);
  color: #211506;
  font: 900 9px/1 Inter, sans-serif;
  letter-spacing: .12em;
  box-shadow: 0 5px 14px rgba(0,0,0,.38);
  opacity: 0;
  transform: translateY(5px) scale(.72);
  pointer-events: none;
}

.build-new-badge.visible {
  animation: newBadgeInOut 2.5s ease both;
}

@keyframes buildUnlockPop {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(.72);
  }
  58% {
    opacity: 1;
    transform: translateY(-3px) scale(1.08);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes newBadgeInOut {
  0% {
    opacity: 0;
    transform: translateY(5px) scale(.72);
  }
  12%,
  72% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-4px) scale(.85);
  }
}

@media (max-width: 980px), (max-height: 650px) {
  .build-grid {
    gap: 6px;
    padding: 9px 9px 7px;
  }
}

@media (max-width: 720px), (max-height: 520px) {
  .build-panel-header {
    padding: 8px 10px 6px;
  }

  .build-grid {
    padding: 7px;
    row-gap: 5px;
  }

  .build-panel-note {
    display: none;
  }
}


/* =========================================================
   V6.3 CINEMATIC PROGRESSION & COMBAT JUICE
   ========================================================= */

.cinematic-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.cinematic-layer.visible {
  visibility: visible;
  animation: cinematicLayerInOut 2.2s ease both;
}

.cinematic-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, transparent 20%, rgba(0,0,0,.22) 64%, rgba(0,0,0,.72) 100%);
}

.cinematic-card {
  position: relative;
  min-width: min(580px, 84vw);
  padding: 24px 48px 27px;
  border-top: 1px solid rgba(246,214,138,.8);
  border-bottom: 1px solid rgba(246,214,138,.8);
  background: linear-gradient(90deg, transparent, rgba(8,15,20,.91) 16%, rgba(8,15,20,.96) 50%, rgba(8,15,20,.91) 84%, transparent);
  text-align: center;
  box-shadow: 0 0 70px rgba(0,0,0,.5);
  transform: translateY(16px) scale(.9);
}

.cinematic-layer.visible .cinematic-card {
  animation: cinematicCardInOut 2.2s cubic-bezier(.2,.8,.2,1) both;
}

.cinematic-kicker {
  display: block;
  margin-bottom: 7px;
  color: #e8bd63;
  font: 900 12px/1 Inter, sans-serif;
  letter-spacing: .3em;
}

.cinematic-title {
  display: block;
  color: #fff4d5;
  font: 800 clamp(32px, 5vw, 68px)/.95 Cinzel, serif;
  letter-spacing: .035em;
  text-shadow: 0 4px 18px rgba(0,0,0,.8);
}

.cinematic-subtitle {
  display: block;
  margin-top: 12px;
  color: #d8d1c3;
  font: 700 12px/1.5 Inter, sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.cinematic-layer[data-mode="boss"] .cinematic-kicker {
  color: #ff715f;
}

.cinematic-layer[data-mode="boss"] .cinematic-card {
  border-color: rgba(255,94,76,.86);
  background: linear-gradient(90deg, transparent, rgba(38,6,10,.92) 16%, rgba(28,5,8,.97) 50%, rgba(38,6,10,.92) 84%, transparent);
}

.cinematic-layer[data-mode="boss"] .cinematic-title {
  color: #ffd6ce;
  text-shadow: 0 0 24px rgba(255,55,35,.38), 0 4px 18px rgba(0,0,0,.8);
}

@keyframes cinematicLayerInOut {
  0% { opacity: 0; }
  12%, 75% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes cinematicCardInOut {
  0% { opacity: 0; transform: translateY(18px) scale(.88); letter-spacing: .14em; }
  18% { opacity: 1; transform: translateY(0) scale(1.03); }
  32%, 72% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-10px) scale(.97); }
}

@media (max-width: 720px), (max-height: 520px) {
  .cinematic-card {
    min-width: 76vw;
    padding: 16px 24px 18px;
  }

  .cinematic-kicker {
    font-size: 9px;
  }

  .cinematic-subtitle {
    font-size: 9px;
  }
}


/* =========================================================
   V6.4.5 CRAZYGAMES VIEWPORT SAFETY
   Final overrides intentionally live last in the stylesheet.
   ========================================================= */

.dialog,
.pause-screen {
  padding: max(10px, env(safe-area-inset-top))
           max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom))
           max(10px, env(safe-area-inset-left));
}

.dialog-card,
.pause-card,
.mod-menu-card {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.screen,
.hud {
  min-width: 0;
  min-height: 0;
}

/* Keep the title and menu inside the visible iframe at every height. */
@media (max-height: 760px) {
  .title-wrap {
    top: clamp(24px, 6vh, 56px);
  }

  .menu-panel {
    bottom: clamp(18px, 4vh, 38px);
  }

  h1 {
    font-size: clamp(44px, 9vh, 82px);
  }

  .tagline {
    margin-top: 14px;
  }
}

@media (max-height: 560px) {
  .title-wrap {
    top: 18px;
  }

  .eyebrow {
    margin-bottom: 7px;
  }

  h1 {
    font-size: clamp(36px, 10vh, 58px);
    line-height: .82;
  }

  .tagline {
    margin-top: 9px;
    font-size: 12px;
  }

  .menu-panel {
    bottom: 14px;
    gap: 5px;
    width: min(290px, 66vw);
  }

  .menu-button {
    min-height: 38px;
    padding: 0 18px;
    font-size: 11px;
  }

  .menu-footer {
    display: none;
  }
}

/* HUD separation for narrow and short CrazyGames embeds. */
@media (max-width: 900px), (max-height: 650px) {
  .day-panel {
    top: var(--safe-edge);
    width: min(280px, 44vw);
  }

  .time-controls {
    top: calc(var(--safe-edge) + 50px * var(--ui-scale));
    right: var(--safe-edge);
  }

  .castle-panel {
    max-width: min(230px, calc(44vw / var(--ui-scale)));
  }

  .resource-panel {
    max-width: min(235px, calc(44vw / var(--ui-scale)));
  }

  .build-panel {
    max-height: calc((100vh - var(--safe-edge) * 2) / var(--ui-scale));
  }

  .build-grid {
    max-height: calc((100vh - 150px) / var(--ui-scale)) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
}

@media (max-width: 720px), (max-height: 520px) {
  .day-panel {
    left: 50%;
    top: 6px;
    width: min(230px, 42vw);
    padding: 7px 10px;
  }

  .time-controls {
    top: 6px;
    right: calc(6px + 42px * var(--ui-scale));
    gap: 4px;
  }

  .pause-button {
    top: 6px;
    right: 6px;
  }

  .special-attack-button,
  .time-speed-button {
    min-width: 72px;
    min-height: 38px;
    padding: 4px 7px;
    font-size: 9px;
  }

  .castle-panel {
    left: 6px;
    top: 6px;
    max-width: min(198px, calc(39vw / var(--ui-scale)));
  }

  .resource-panel {
    left: 6px;
    bottom: 6px;
    min-width: 176px;
    max-width: min(205px, calc(41vw / var(--ui-scale)));
  }

  .build-panel {
    right: 6px;
    bottom: 6px;
    --build-panel-width: 276px;
  }

  .build-panel-header {
    padding: 7px 9px 5px;
  }

  .build-grid {
    padding: 6px;
    gap: 5px;
    max-height: calc((100vh - 112px) / var(--ui-scale)) !important;
  }

  .build-card {
    --build-card-width: 112px;
    min-height: 58px;
  }

  .resource-panel-header small,
  .build-panel-header small,
  .build-copy small,
  .build-panel-note,
  #castle-upgrade-note {
    display: none !important;
  }
}

/* Extreme iframe fallback. Gameplay stays usable instead of overlapping. */
@media (max-width: 560px), (max-height: 430px) {
  :root {
    --safe-edge: 4px;
  }

  .day-panel {
    width: min(190px, 39vw);
    grid-template-columns: auto 1fr;
    gap: 6px;
  }

  .day-panel #day-count {
    display: none;
  }

  .time-controls {
    top: 4px;
    right: calc(4px + 38px * var(--ui-scale));
  }

  .pause-button {
    top: 4px;
    right: 4px;
    width: 38px;
    height: 38px;
  }

  .special-attack-button,
  .time-speed-button {
    min-width: 64px;
    min-height: 34px;
  }

  .special-attack-button span,
  .time-speed-button span {
    display: none;
  }

  .castle-panel {
    top: 4px;
    left: 4px;
    max-width: min(180px, calc(36vw / var(--ui-scale)));
  }

  .resource-panel {
    left: 4px;
    bottom: 4px;
    min-width: 160px;
    max-width: min(184px, calc(38vw / var(--ui-scale)));
    padding: 7px 9px;
  }

  .resource-row {
    min-height: 28px;
  }

  .build-panel {
    right: 4px;
    bottom: 4px;
    --build-panel-width: 238px;
  }

  .build-panel-header {
    display: none;
  }

  .build-grid {
    padding: 5px;
    max-height: calc((100vh - 18px) / var(--ui-scale)) !important;
  }

  .build-card {
    --build-card-width: 98px;
    min-height: 52px;
  }

  .build-icon {
    font-size: 22px;
  }

  .build-cost {
    font-size: 10px;
  }

  .world-intro {
    top: 10%;
    min-width: min(420px, 86vw);
    padding: 12px 16px;
  }

  .dialog-card,
  .pause-card,
  .mod-menu-card {
    width: min(94vw, 560px);
    max-height: 92vh;
    padding: 20px;
  }

  .dialog-card h2,
  .pause-card h2 {
    margin-bottom: 12px;
    font-size: 26px;
  }
}

/* Portrait fallback is not the preferred CrazyGames layout, but remains usable. */
@media (orientation: portrait) and (max-width: 760px) {
  .title-wrap {
    left: 7vw;
    top: 7vh;
  }

  .menu-panel {
    left: 7vw;
    bottom: 7vh;
    width: min(330px, 86vw);
  }

  .day-panel {
    width: 46vw;
  }

  .time-controls {
    top: calc(var(--safe-edge) + 48px * var(--ui-scale));
  }
}

/* =========================================================
   V7.0 QUALITY UPDATE
   Finished-game onboarding, tactical placement and results.
   ========================================================= */

.menu-records {
  position: absolute;
  left: clamp(390px, 31vw, 520px);
  bottom: clamp(58px, 9vh, 104px);
  display: flex;
  gap: 10px;
  color: rgba(255,255,255,.72);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.menu-records span {
  min-width: 118px;
  padding: 10px 12px;
  border-left: 2px solid rgba(232,189,97,.72);
  background: linear-gradient(90deg, rgba(7,17,29,.76), transparent);
}

.menu-records strong {
  display: block;
  margin-top: 4px;
  color: #fff1c5;
  font: 700 18px Cinzel, Georgia, serif;
  letter-spacing: 0;
}

.placement-prompt {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: calc(22px + 155px * var(--ui-scale, 1));
  transform: translateX(-50%);
  display: grid;
  gap: 3px;
  min-width: min(440px, 76vw);
  padding: 11px 20px;
  border: 1px solid rgba(255,225,147,.72);
  background: linear-gradient(180deg, rgba(15,27,36,.95), rgba(5,13,20,.94));
  box-shadow: 0 12px 38px rgba(0,0,0,.46), inset 0 0 20px rgba(232,189,97,.06);
  text-align: center;
  pointer-events: none;
  animation: placementPulse 1.8s ease-in-out infinite;
}

.placement-prompt strong {
  color: #f1ca74;
  font: 700 15px Cinzel, Georgia, serif;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.placement-prompt span {
  color: #d9e0e5;
  font-size: 10px;
  letter-spacing: .05em;
}

body.placing-defence #game-canvas { cursor: crosshair; }
body.placing-defence .build-card.selected {
  box-shadow: 0 0 0 2px #fff3bd, 0 0 24px rgba(255,216,116,.55);
}

@keyframes placementPulse {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}

.tutorial-overlay {
  position: absolute;
  inset: 0;
  z-index: 42;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 42%, rgba(31,48,61,.55), rgba(1,6,10,.86));
  backdrop-filter: blur(7px);
}

.tutorial-card,
.game-over-card {
  width: min(590px, 92vw);
  padding: clamp(26px, 5vw, 46px);
  border: 1px solid #c49a55;
  background:
    linear-gradient(180deg, rgba(26,43,57,.98), rgba(7,16,25,.98)),
    radial-gradient(circle at 50% 0%, rgba(236,190,99,.12), transparent 46%);
  box-shadow: 0 34px 100px rgba(0,0,0,.72), inset 0 0 0 1px rgba(255,234,180,.08);
  text-align: center;
}

.tutorial-kicker {
  display: block;
  margin-bottom: 9px;
  color: #e7bc64;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .28em;
}

.tutorial-card h2,
.game-over-card h2 {
  margin: 0 0 16px;
  color: #fff0c2;
  font: 800 clamp(32px, 6vw, 54px) Cinzel, Georgia, serif;
  line-height: 1;
}

.tutorial-card p,
.game-over-summary {
  margin: 0 auto;
  max-width: 470px;
  color: #d9e2e7;
  line-height: 1.65;
}

.tutorial-actions {
  display: grid;
  grid-template-columns: .65fr 1.35fr;
  gap: 10px;
  margin-top: 28px;
}

.tutorial-actions button,
.settings-action {
  min-height: 48px;
  border: 1px solid rgba(226,190,113,.42);
  background: rgba(7,17,29,.86);
  color: #e8edf0;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
}

.tutorial-actions button.primary {
  border-color: #ffe0a0;
  background: linear-gradient(90deg, #d9a64e, #f0d286);
  color: #171109;
}

.tutorial-highlight {
  position: relative;
  z-index: 2;
  animation: tutorialHighlight 1.15s ease-in-out infinite;
}

@keyframes tutorialHighlight {
  0%, 100% { box-shadow: 0 0 0 2px #fff0a8, 0 0 14px rgba(255,219,119,.45); }
  50% { box-shadow: 0 0 0 4px #fff4c6, 0 0 32px rgba(255,219,119,.85); }
}

.game-over-screen {
  z-index: 24;
  background:
    radial-gradient(circle at 50% 44%, rgba(100,25,17,.22), transparent 36%),
    rgba(1,5,9,.84);
  backdrop-filter: blur(8px);
}

.game-over-screen.active {
  display: grid;
  place-items: center;
  padding: 18px;
}

.game-over-card .eyebrow { margin-bottom: 12px; }
.game-over-card .menu-button { margin-top: 10px; text-align: center; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 24px 0 16px;
}

.result-grid span {
  padding: 13px;
  border: 1px solid rgba(226,190,113,.22);
  background: rgba(3,10,17,.42);
  color: #aebbc3;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.result-grid strong {
  display: block;
  margin-top: 5px;
  color: #ffe7a5;
  font: 700 24px Cinzel, Georgia, serif;
  letter-spacing: 0;
}

.result-record {
  margin: 0 0 18px;
  color: #e7bc64;
  font: 700 14px Cinzel, Georgia, serif;
}

.save-indicator {
  position: absolute;
  z-index: 12;
  right: 24px;
  bottom: 18px;
  padding: 8px 12px;
  border: 1px solid rgba(232,189,97,.38);
  background: rgba(5,13,20,.86);
  color: #e9d39c;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.save-indicator.visible {
  animation: saveIndicator 1.3s ease both;
}

@keyframes saveIndicator {
  0% { opacity: 0; transform: translateY(8px); }
  20%, 72% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-4px); }
}

.how-to-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.how-to-grid article {
  padding: 14px;
  border: 1px solid rgba(226,190,113,.2);
  background: rgba(3,10,17,.36);
}

.how-to-grid strong { color: #efc978; }
.how-to-grid p { margin: 6px 0 0; font-size: 12px; }
.dialog-tip { margin-bottom: 0; font-size: 12px; }

.settings-grid {
  display: grid;
  gap: 12px;
}

.settings-grid > label {
  display: grid;
  gap: 9px;
  padding: 12px 14px;
  border: 1px solid rgba(226,190,113,.18);
  background: rgba(3,10,17,.34);
  color: #e0e7eb;
  font-size: 12px;
  font-weight: 700;
}

.settings-grid label > span {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.settings-grid input[type="range"] { width: 100%; accent-color: #dca94f; }
.settings-grid .setting-toggle {
  grid-template-columns: 1fr auto;
  align-items: center;
}
.settings-grid .setting-toggle span { display: block; }
.settings-grid input[type="checkbox"] {
  width: 21px;
  height: 21px;
  accent-color: #dca94f;
}
.settings-action.subtle { opacity: .78; }

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}

@media (max-width: 900px), (max-height: 650px) {
  .menu-records { display: none; }
  .placement-prompt {
    bottom: calc(8px + 112px * var(--ui-scale, 1));
    min-width: min(380px, 66vw);
    padding: 8px 12px;
  }
  .placement-prompt span { display: none; }
}

@media (max-width: 620px), (max-height: 500px) {
  .tutorial-card,
  .game-over-card { padding: 22px; max-height: 94vh; overflow-y: auto; }
  .tutorial-card h2,
  .game-over-card h2 { font-size: 30px; }
  .tutorial-card p,
  .game-over-summary { font-size: 12px; }
  .result-grid { gap: 6px; margin: 15px 0 12px; }
  .result-grid span { padding: 8px; }
  .result-grid strong { font-size: 18px; }
  .how-to-grid { grid-template-columns: 1fr; }
  .placement-prompt { bottom: 64px; min-width: min(300px, 58vw); }
}

@media (max-height: 620px) {
  .tutorial-card,
  .game-over-card {
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    padding: 22px 34px;
  }

  .game-over-card h2 {
    margin-bottom: 8px;
    font-size: 42px;
  }

  .game-over-summary {
    line-height: 1.4;
  }

  .result-grid {
    margin: 14px 0 10px;
    gap: 7px;
  }

  .result-grid span {
    padding: 8px 10px;
  }

  .result-grid strong {
    font-size: 19px;
  }

  .result-record {
    margin-bottom: 10px;
  }

  .game-over-card .menu-button {
    min-height: 42px;
    margin-top: 7px;
  }
}

/* Royal Decree progression */
.next-day-panel {
  width: min(760px, calc(100vw - 30px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 22px;
}

.next-day-panel h2 {
  margin: 0 0 14px;
  color: #f1cc79;
  font: 800 clamp(24px, 4vw, 36px) Cinzel, Georgia, serif;
}

.decree-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.next-day-panel .decree-card {
  width: 100%;
  min-height: 150px;
  padding: 16px 14px;
  border: 1px solid rgba(241,207,128,.32);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(27,41,52,.96), rgba(8,17,25,.96));
  color: #eef2f4;
  font-family: Inter, system-ui, sans-serif;
  cursor: pointer;
  box-shadow: none;
}

.next-day-panel .decree-card:hover:not(:disabled) {
  filter: brightness(1.12);
  transform: translateY(-2px);
}

.next-day-panel .decree-card.selected {
  border-color: #ffe29a;
  box-shadow: 0 0 0 2px rgba(255,226,154,.22), 0 0 28px rgba(232,189,97,.18);
}

.next-day-panel .decree-card:disabled:not(.selected) {
  opacity: .38;
  cursor: default;
}

.decree-icon {
  display: block;
  margin-bottom: 8px;
  color: #efc76f;
  font-size: 28px;
}

.decree-card strong {
  display: block;
  color: #fff0c2;
  font: 700 15px Cinzel, Georgia, serif;
}

.decree-card small {
  display: block;
  margin-top: 8px;
  color: #bcc7ce;
  font-size: 11px;
  line-height: 1.45;
}

.next-day-panel .decree-summary {
  margin: 13px 0 12px;
  color: #d3c8af;
  text-transform: none;
  letter-spacing: .03em;
  font-size: 11px;
}

.next-day-panel .start-next-day-button {
  min-height: 50px;
  font-size: 17px;
}

.next-day-panel .start-next-day-button:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(.6);
}

@media (max-width: 720px), (max-height: 560px) {
  .next-day-panel {
    width: min(650px, calc(100vw - 18px));
    padding: 14px;
  }

  .next-day-panel h2 { margin-bottom: 9px; font-size: 24px; }
  .decree-grid { gap: 6px; }
  .next-day-panel .decree-card { min-height: 104px; padding: 9px; }
  .decree-icon { margin-bottom: 4px; font-size: 21px; }
  .decree-card strong { font-size: 12px; }
  .decree-card small { margin-top: 4px; font-size: 9px; line-height: 1.3; }
  .next-day-panel .decree-summary { margin: 8px 0; font-size: 9px; }
  .next-day-panel .start-next-day-button { min-height: 40px; font-size: 14px; }
}

@media (max-width: 520px) {
  .decree-grid { grid-template-columns: 1fr; }
}
