:root {
  color-scheme: dark;
  --ink: #f2e8cf;
  --muted: #c8baa0;
  --gold: #d8ad4b;
  --gold2: #f3d984;
  --blood: #8f2f28;
  --blue: #315d88;
  --green: #59723d;
  --panel: rgba(15, 20, 15, .93);
  --edge: rgba(224, 190, 104, .38);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: #0b110d; font-family: Georgia, "Times New Roman", serif; color: var(--ink); touch-action: none; }
button, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
#app, #game { width: 100%; height: 100%; }
#game { display: block; background: #243722; cursor: crosshair; }

.screen, .modal, .hud { position: fixed; inset: 0; }
.start-screen { display: none; place-items: center; background: #121a13 url("assets/abertura-reinos.png") center/cover no-repeat; z-index: 20; overflow: auto; padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom)); }
.start-screen.active { display: grid; }
.start-shade { position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(15,20,14,.22) 0 25%, rgba(7,10,8,.74) 75%), linear-gradient(90deg, rgba(8,15,14,.45), transparent 35% 65%, rgba(19,8,6,.48)); backdrop-filter: saturate(.9); }
.start-content { position: relative; width: min(760px, 100%); text-align: center; animation: reveal .8s ease both; }
.eyebrow, .panel-kicker { display: block; margin: 0 0 8px; color: var(--gold2); text-transform: uppercase; letter-spacing: .24em; font: 700 .75rem/1 system-ui, sans-serif; text-shadow: 0 2px 8px #000; }
h1 { margin: 0; filter: drop-shadow(0 7px 10px #000); line-height: .83; }
h1 span, h1 b { display: block; }
h1 span { font-size: clamp(2.5rem, 9vw, 5.8rem); letter-spacing: .08em; color: #f4e9c7; }
h1 b { font-size: clamp(1.25rem, 4.3vw, 2.8rem); letter-spacing: .36em; color: var(--gold); padding-left: .36em; margin-top: 11px; }
.start-copy { margin: 24px auto 20px; max-width: 620px; font: 600 clamp(.95rem, 2.2vw, 1.25rem)/1.4 system-ui, sans-serif; color: #fff7e3; text-shadow: 0 2px 8px #000; }

.faction-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin: 0 auto 14px; max-width: 680px; }
.faction-card { min-height: 86px; border: 1px solid rgba(255,255,255,.18); border-radius: 5px; background: linear-gradient(135deg, rgba(15,25,31,.92), rgba(11,14,12,.86)); display: flex; align-items: center; gap: 14px; text-align: left; padding: 12px 15px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.8), 0 10px 30px rgba(0,0,0,.28); transition: .18s ease; }
.faction-card:last-child { background: linear-gradient(135deg, rgba(34,18,13,.92), rgba(11,14,12,.86)); }
.faction-card.selected { border-color: var(--gold2); transform: translateY(-2px); box-shadow: inset 0 0 0 1px #3f2c11, 0 0 22px rgba(234,185,73,.32); }
.faction-seal { width: 54px; aspect-ratio: 1; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; font-size: 1.75rem; border: 2px solid rgba(255,255,255,.26); background: #213f60; box-shadow: inset 0 0 12px #0008; }
.orc-seal { background: #682c25; }
.faction-card strong, .faction-card small { display: block; }
.faction-card strong { font-size: 1.16rem; color: #fff5d9; }
.faction-card small { margin-top: 5px; font: 500 .76rem/1.3 system-ui, sans-serif; color: #d2c9b7; }
.start-row { display: flex; align-items: end; justify-content: center; gap: 12px; }
.difficulty-label { display: grid; gap: 5px; text-align: left; text-transform: uppercase; letter-spacing: .1em; font: 700 .65rem/1 system-ui,sans-serif; color: #d5c8ad; }
select { height: 50px; min-width: 155px; border: 1px solid var(--edge); border-radius: 3px; background: #111912; color: #f7ecd2; padding: 0 34px 0 12px; }
.primary-btn, .secondary-btn, .danger-btn { min-height: 50px; border-radius: 3px; padding: 0 24px; border: 1px solid #e5bf64; background: linear-gradient(#d9ae4d,#9a681e); color: #1b1408; font: 900 .82rem/1 system-ui,sans-serif; letter-spacing: .1em; cursor: pointer; box-shadow: inset 0 1px #fff7, 0 5px 15px #0007; }
.primary-btn:hover { filter: brightness(1.1); }
.secondary-btn { border-color: #786c52; background: linear-gradient(#303a30,#1a211b); color: #eee2c5; }
.danger-btn { border-color: #8e4137; background: linear-gradient(#612721,#391714); color: #f0d7cf; }
.text-btn { border: 0; background: none; color: #f0d58a; text-decoration: underline; margin-top: 12px; cursor: pointer; }
.legal-note { font: 500 .65rem/1.3 system-ui,sans-serif; color: #acaa9e; text-shadow: 0 1px 3px #000; }

.hud { z-index: 5; pointer-events: none; }
.hud button, .hud .selection-panel, .hud .action-bar, .hud .minimap, .hud .camera-controls { pointer-events: auto; }
.topbar { position: absolute; z-index: 4; top: calc(8px + var(--safe-top)); left: 50%; transform: translateX(-50%); height: 54px; width: min(820px, calc(100% - 18px)); display: flex; align-items: center; padding: 4px 6px 4px 54px; border: 1px solid var(--edge); background: linear-gradient(180deg, rgba(31,39,30,.97), rgba(12,17,13,.94)); box-shadow: 0 6px 20px #0009, inset 0 1px #fff1; border-radius: 5px; }
.crest { position: absolute; left: -4px; width: 54px; height: 62px; display: grid; place-items: center; font-size: 1.7rem; background: linear-gradient(#3f6c9b,#17314e); border: 2px solid #d0aa57; clip-path: polygon(7% 0,93% 0,100% 77%,50% 100%,0 77%); text-shadow: 0 2px #000; }
.resource { height: 40px; min-width: 92px; display: grid; grid-template-columns: 22px 1fr; grid-template-rows: 22px 13px; column-gap: 5px; padding: 1px 10px; border-right: 1px solid #ffffff18; font: 800 .95rem/1.2 system-ui,sans-serif; }
.resource i { grid-row: 1/3; align-self: center; width: 20px; height: 20px; background: #c99b39; border: 2px solid #edd48a; transform: rotate(45deg); box-shadow: inset 0 0 5px #6a4612; }
.resource.wood i { border-radius: 50%; transform: none; background: #7c4a22; border-color: #b98347; }
.resource.food i { border-radius: 50% 50% 4px 4px; transform: none; background: #809459; border-color: #b7c77c; }
.resource small { font: 500 .6rem/1 system-ui,sans-serif; color: #aca78f; text-transform: uppercase; letter-spacing: .09em; }
.objective { flex: 1; min-width: 0; padding: 0 10px; text-align: center; color: #d6caa9; font: 600 .76rem/1.2 system-ui,sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid #696751; background: linear-gradient(#313a2f,#171d18); color: #efe5cb; margin-left: 4px; border-radius: 3px; font: 800 1rem/1 system-ui,sans-serif; cursor: pointer; }

.selection-panel { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: calc(10px + var(--safe-bottom)); width: 290px; min-height: 92px; display: flex; gap: 11px; padding: 9px; border: 1px solid var(--edge); border-radius: 5px; background: var(--panel); box-shadow: 0 6px 24px #0009; }
.selection-panel.empty { opacity: .78; }
.portrait { width: 72px; height: 72px; flex: 0 0 auto; display: grid; place-items: center; background: radial-gradient(circle,#485443,#151b16); border: 2px solid #887948; color: #e8cc72; font-size: 2rem; overflow: hidden; }
.selection-info { flex: 1; min-width: 0; font: 500 .72rem/1.35 system-ui,sans-serif; color: #bbb49f; }
.selection-info strong { display: block; color: #f6edd7; font: 700 1rem/1.2 Georgia,serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.health-track { height: 9px; margin: 9px 0 6px; background: #301313; border: 1px solid #080808; }
.health-track span { display: block; height: 100%; width: 0; background: linear-gradient(90deg,#418f41,#76bb55); transition: width .15s; }
.action-bar { position: absolute; bottom: calc(10px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); display: flex; justify-content: center; gap: 5px; max-width: min(520px, calc(100% - 650px)); padding: 7px; border: 1px solid var(--edge); background: var(--panel); border-radius: 5px; box-shadow: 0 6px 24px #0009; overflow-x: auto; }
.action { position: relative; min-width: 62px; width: 62px; height: 66px; display: grid; place-items: center; align-content: center; gap: 2px; border: 1px solid #64604c; border-radius: 3px; background: linear-gradient(#354034,#171d18); color: #f4e6c5; cursor: pointer; }
.action:hover { border-color: #d9b458; }
.action:disabled { filter: grayscale(.8); opacity: .44; }
.action .glyph { font-size: 1.45rem; line-height: 1; }
.action .label { max-width: 58px; font: 700 .56rem/1.05 system-ui,sans-serif; text-transform: uppercase; }
.action .cost { color: #dbbd6e; font: 600 .5rem/1 system-ui,sans-serif; }
.action .hotkey { position: absolute; top: 2px; left: 4px; font: 600 .5rem/1 system-ui,sans-serif; color: #9d9b8c; }

.minimap { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: calc(10px + var(--safe-bottom)); width: 220px; height: 140px; border: 2px solid #8c7642; background: #21341e; box-shadow: 0 5px 22px #000b; cursor: pointer; }
.camera-controls { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: calc(158px + var(--safe-bottom)); display: flex; }
.camera-controls button { width: 42px; height: 34px; border: 1px solid #665f49; background: #151c16eF; color: #eee0bf; cursor: pointer; }
.toast { position: absolute; z-index: 8; left: 50%; top: calc(74px + var(--safe-top)); transform: translate(-50%,-10px); padding: 9px 16px; border: 1px solid #bd9b4c; border-radius: 3px; background: rgba(16,20,15,.94); color: #f3e6c5; font: 700 .78rem/1.2 system-ui,sans-serif; opacity: 0; transition: .2s; box-shadow: 0 5px 20px #0008; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.build-hint { position: absolute; left: 50%; bottom: calc(94px + var(--safe-bottom)); transform: translateX(-50%); padding: 8px 12px; border-radius: 3px; background: #101610dd; border: 1px solid #d2a844; font: 700 .7rem/1.2 system-ui,sans-serif; color: #f5e3b4; }
.selection-box { position: absolute; border: 1px solid #e2c35b; background: rgba(203,183,80,.12); pointer-events: none; }

.modal { z-index: 30; display: grid; place-items: center; padding: 18px; background: rgba(4,7,5,.76); backdrop-filter: blur(7px); }
.panel { width: min(510px, 100%); max-height: 90vh; overflow: auto; padding: 28px; text-align: center; border: 1px solid #9b8247; background: linear-gradient(145deg,#263024,#111712 65%); box-shadow: inset 0 0 0 3px #0b0e0b, 0 22px 80px #000; }
.panel h2 { margin: 5px 0 18px; color: #fff1ce; font-size: 2.35rem; }
.tutorial-steps { display: grid; gap: 8px; text-align: left; }
.tutorial-steps article { display: flex; align-items: center; gap: 12px; padding: 10px; background: #ffffff08; border: 1px solid #ffffff10; }
.tutorial-steps b { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: #b4832e; color: #1b1206; font: 900 1rem/1 system-ui,sans-serif; }
.tutorial-steps strong, .tutorial-steps span { display: block; }
.tutorial-steps strong { color: #f0d88e; margin-bottom: 2px; }
.tutorial-steps span { color: #c9c2ad; font: .8rem/1.3 system-ui,sans-serif; }
.touch-tip { color: #aaa692; font: .72rem/1.45 system-ui,sans-serif; }
.menu-panel { display: grid; gap: 9px; width: min(370px,100%); }
.menu-panel h2 { margin-bottom: 10px; }
.battle-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; margin: 17px 0; }
.battle-stats div { padding: 9px 4px; background: #ffffff09; border: 1px solid #ffffff13; }
.battle-stats b,.battle-stats small { display: block; }
.battle-stats b { color: #e7c66b; font: 800 1.25rem/1 system-ui,sans-serif; }
.battle-stats small { margin-top: 5px; color: #aaa58f; font: 600 .58rem/1.1 system-ui,sans-serif; text-transform: uppercase; }
.end-panel .primary-btn,.end-panel .secondary-btn { margin: 4px; }

@keyframes reveal { from { opacity: 0; transform: translateY(12px) scale(.98); } }

@media (max-width: 760px), (max-height: 540px) {
  .start-screen { align-items: start; }
  .start-content { padding-top: 2px; }
  .eyebrow { font-size: .58rem; }
  h1 span { font-size: clamp(2.25rem,11vw,4rem); }
  h1 b { font-size: clamp(1rem,5vw,1.8rem); }
  .start-copy { margin: 14px auto 12px; font-size: .82rem; }
  .faction-card { min-height: 69px; padding: 8px; gap: 8px; }
  .faction-seal { width: 43px; font-size: 1.3rem; }
  .faction-card strong { font-size: .95rem; }
  .faction-card small { font-size: .63rem; }
  .start-row { align-items: stretch; }
  .difficulty-label { flex: 0 0 38%; }
  select, .primary-btn { min-width: 0; min-height: 46px; height: 46px; font-size: .69rem; padding: 0 10px; }
  .topbar { top: var(--safe-top); width: 100%; height: 48px; border-radius: 0; border-left: 0; border-right: 0; padding-left: 43px; padding-right: 3px; }
  .crest { width: 44px; height: 52px; font-size: 1.3rem; }
  .resource { min-width: 65px; height: 34px; grid-template-columns: 16px 1fr; grid-template-rows: 19px 11px; padding: 0 5px; font-size: .75rem; }
  .resource i { width: 14px; height: 14px; border-width: 1px; }
  .resource small { font-size: .48rem; }
  .objective { display: none; }
  .icon-btn { width: 33px; height: 34px; margin-left: 2px; }
  .selection-panel { left: 6px; bottom: calc(6px + var(--safe-bottom)); width: 178px; min-height: 64px; height: 64px; padding: 5px; gap: 6px; }
  .portrait { width: 51px; height: 51px; font-size: 1.35rem; }
  .selection-info strong { font-size: .78rem; }
  .selection-info { font-size: .57rem; }
  .health-track { height: 7px; margin: 5px 0 3px; }
  .action-bar { bottom: calc(76px + var(--safe-bottom)); left: 6px; right: 6px; transform: none; max-width: none; justify-content: flex-start; padding: 4px; scrollbar-width: none; }
  .action-bar:empty { display: none; }
  .action { min-width: 55px; width: 55px; height: 56px; }
  .action .glyph { font-size: 1.2rem; }
  .action .label { font-size: .5rem; }
  .action .cost { font-size: .44rem; }
  .minimap { width: 116px; height: 74px; right: 6px; bottom: calc(6px + var(--safe-bottom)); }
  .camera-controls { right: 6px; bottom: calc(86px + var(--safe-bottom)); }
  .camera-controls button { width: 37px; height: 30px; }
  .build-hint { bottom: calc(139px + var(--safe-bottom)); width: max-content; max-width: 92%; text-align: center; }
  .toast { top: calc(56px + var(--safe-top)); font-size: .68rem; }
  .panel { padding: 20px; }
  .panel h2 { font-size: 1.75rem; }
}

@media (max-width: 480px) {
  .faction-grid { grid-template-columns: 1fr; gap: 7px; }
  .faction-card { min-height: 62px; }
  .faction-card small { margin-top: 2px; }
  .legal-note { display: none; }
  .start-row { flex-direction: column; }
  .difficulty-label { width: 100%; }
  select { width: 100%; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .start-screen { padding: 8px 16px; }
  .start-content { max-width: 800px; }
  .start-copy { display: none; }
  .faction-grid { margin-top: 12px; margin-bottom: 8px; }
  .faction-card { min-height: 58px; }
  .faction-seal { width: 38px; }
  .legal-note { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
