/* =========================================================================
   Quest for Glory II: Trial by Fire — HTML5 demo
   style.css — desert / EGA-inspired theme
   ========================================================================= */

:root {
  --sand:        #d9a441;
  --sand-dark:   #b3792a;
  --dune:        #e8c887;
  --night:       #1a1030;
  --night-2:     #2b1a4a;
  --sky-dusk:    #7a3b6b;
  --ink:         #14100c;
  --parchment:   #f2e2bd;
  --parchment-2: #e3ca8f;
  --blood:       #8a2b1f;
  --gold:        #f4c542;
  --teal:        #2e8b8b;
  --shadow:      rgba(0,0,0,0.45);
  --font-body:   Georgia, 'Times New Roman', serif;
  --font-head:   'Trajan Pro', 'Georgia', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;               /* the game owns the whole viewport */
  background: #0c0a12;
  color: var(--parchment);
  font-family: var(--font-body);
}

/* The game frame fills the entire browser window. */
#game-frame {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: var(--night);
  overflow: hidden;
}

/* ---------- screen system ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade 0.35s ease;
}
.screen.active { display: flex; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--parchment);
  background: linear-gradient(#3a2a5a, #241640);
  border: 2px solid var(--sand-dark);
  border-radius: 5px;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, box-shadow 0.2s ease;
  letter-spacing: 0.02em;
}
.btn:hover { background: linear-gradient(#4a366e, #2e1d52); box-shadow: 0 0 12px rgba(244,197,66,0.35); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn-primary {
  background: linear-gradient(var(--sand), var(--sand-dark));
  color: var(--ink);
  border-color: var(--gold);
  font-weight: bold;
}
.btn-primary:hover { background: linear-gradient(#e8b451, #c2862f); }

.link-btn {
  background: none; border: none; color: var(--gold);
  cursor: pointer; font-family: var(--font-body); font-size: inherit;
  text-decoration: underline; padding: 0;
}

/* ============================ TITLE SCREEN ============================ */
#screen-title {
  background:
    radial-gradient(ellipse at 50% 120%, var(--sand-dark) 0%, transparent 55%),
    linear-gradient(var(--night) 0%, var(--sky-dusk) 78%, var(--sand-dark) 100%);
}
.title-stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 20% 18%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 70% 12%, #fff, transparent),
    radial-gradient(1px 1px at 45% 30%, #ffe, transparent),
    radial-gradient(1px 1px at 85% 25%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 32% 8%, #fff, transparent),
    radial-gradient(1px 1px at 60% 34%, #ffd, transparent);
  opacity: 0.8;
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.55; } to { opacity: 0.95; } }
.title-content { position: relative; text-align: center; z-index: 1; }
.title-kicker { font-size: 13px; letter-spacing: 0.25em; text-transform: uppercase; color: var(--dune); margin: 0 0 4px; }
.title-main {
  font-family: var(--font-head);
  font-size: 46px; margin: 0; line-height: 1;
  color: var(--gold);
  text-shadow: 0 2px 0 var(--blood), 0 4px 10px rgba(0,0,0,0.6);
  letter-spacing: 0.04em;
}
.title-main .numeral { color: var(--parchment); }
.title-sub {
  font-family: var(--font-head);
  font-size: 26px; margin: 2px 0 0; color: var(--parchment);
  letter-spacing: 0.3em; text-transform: uppercase;
}
.title-tag { font-style: italic; color: var(--dune); margin: 14px 0 22px; }
.title-menu { display: flex; flex-direction: column; gap: 10px; width: 260px; margin: 0 auto; }
.title-footer { margin-top: 22px; font-size: 11px; color: rgba(242,226,189,0.5); }

/* ============================ PANELS ============================ */
.panel {
  width: 100%; max-width: 620px;
  background: linear-gradient(var(--parchment), var(--parchment-2));
  color: var(--ink);
  border: 3px solid var(--sand-dark);
  border-radius: 8px;
  padding: 22px 26px;
  box-shadow: 0 10px 30px var(--shadow);
  max-height: 100%;
  overflow-y: auto;
}
.panel-title { font-family: var(--font-head); margin: 0 0 4px; color: var(--blood); font-size: 26px; }
.panel-lead { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
#screen-create, #screen-import { background: linear-gradient(var(--night), var(--night-2)); }

/* ---------- class grid ---------- */
.class-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.class-card {
  background: rgba(255,255,255,0.4);
  border: 2px solid var(--sand-dark);
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
  text-align: center;
}
.class-card:hover { transform: translateY(-3px); box-shadow: 0 6px 16px var(--shadow); }
.class-card.selected { border-color: var(--blood); background: rgba(244,197,66,0.35); box-shadow: 0 0 0 2px var(--gold); }
.class-icon { font-size: 34px; line-height: 1; }
.class-name { font-family: var(--font-head); font-size: 18px; margin: 6px 0 4px; color: var(--blood); }
.class-desc { font-size: 12px; line-height: 1.4; color: #3a2c18; }

.create-footer { margin-top: 18px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.name-field { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
.name-field input {
  font-family: var(--font-body); font-size: 16px; padding: 7px 10px;
  border: 2px solid var(--sand-dark); border-radius: 5px; background: #fff; color: var(--ink); width: 180px;
}
.create-actions { display: flex; gap: 10px; }

/* ---------- import ---------- */
#import-code {
  width: 100%; font-family: 'Courier New', monospace; font-size: 13px;
  padding: 10px; border: 2px solid var(--sand-dark); border-radius: 6px;
  background: #fff; color: var(--ink); resize: vertical; margin-bottom: 8px;
}
.import-msg { min-height: 20px; font-size: 13px; margin-bottom: 12px; }
.import-msg.ok { color: #1d6b2e; }
.import-msg.err { color: var(--blood); }

/* ============================ GAME SCREEN ============================ */
#screen-game { padding: 0; justify-content: flex-start; background: #0a0810; }
.hud {
  width: 100%; display: flex; flex-wrap: wrap; gap: 6px 14px;
  padding: 8px 12px; background: linear-gradient(#241640, #1a1030);
  border-bottom: 2px solid var(--sand-dark); font-size: 12px; color: var(--dune);
}
.hud .stat { display: inline-flex; align-items: baseline; gap: 4px; }
.hud .stat b { color: var(--gold); font-family: var(--font-head); }
.hud .stat .val { color: var(--parchment); font-weight: bold; }

#game-canvas {
  display: block; width: 100%; height: 100%; flex: 1 1 auto; min-height: 0;
  image-rendering: pixelated; background: #0a0810; outline: none;
}
.message-box {
  width: 100%; min-height: 54px; background: rgba(20,16,12,0.92);
  border-top: 2px solid var(--sand-dark); padding: 10px 16px; color: var(--parchment);
}
.message-box p { margin: 0; font-size: 14px; line-height: 1.45; }
.controls-hint {
  width: 100%; padding: 6px 12px; background: #12101a; font-size: 11px;
  color: rgba(242,226,189,0.7); text-align: center; border-top: 1px solid #000;
}
kbd {
  background: #2b1a4a; border: 1px solid var(--sand-dark); border-radius: 3px;
  padding: 0 5px; font-family: var(--font-body); font-size: 11px; color: var(--parchment);
}
.vol { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
.vol input[type="range"] {
  width: 72px; height: 4px; accent-color: var(--gold); cursor: pointer; vertical-align: middle;
}

/* ============================ OVERLAYS ============================ */
.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(6,4,10,0.72); z-index: 20; padding: 20px;
}
.overlay.open { display: flex; animation: fade 0.25s ease; }
.sheet {
  width: 100%; max-width: 460px; max-height: 92%; overflow-y: auto;
  background: linear-gradient(var(--parchment), var(--parchment-2));
  color: var(--ink); border: 3px solid var(--sand-dark); border-radius: 8px;
  padding: 20px 24px; box-shadow: 0 14px 40px rgba(0,0,0,0.6);
}
.sheet h2 { font-family: var(--font-head); color: var(--blood); margin: 0 0 12px; }
.about-sheet p { font-size: 14px; line-height: 1.55; }
.muted { color: #6a5636; font-size: 12px; }

/* character sheet layout */
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-head .avatar { font-size: 40px; }
.sheet-head h3 { margin: 0; font-family: var(--font-head); color: var(--blood); font-size: 22px; }
.sheet-head .cls { font-size: 13px; color: #5a4626; }
.stat-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; margin-bottom: 14px; }
.stat-row { display: flex; justify-content: space-between; font-size: 14px; border-bottom: 1px dotted var(--sand-dark); padding: 3px 0; }
.stat-row span:last-child { font-weight: bold; color: var(--blood); }
.bar-wrap { margin: 8px 0; }
.bar-label { font-size: 12px; display: flex; justify-content: space-between; margin-bottom: 2px; }
.bar { height: 12px; background: rgba(0,0,0,0.18); border: 1px solid var(--sand-dark); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; }
.bar.hp > i  { background: linear-gradient(90deg, #8a2b1f, #d9534f); }
.bar.mp > i  { background: linear-gradient(90deg, #2e5c8b, #4a9fd9); }
.bar.stam > i{ background: linear-gradient(90deg, #4a7c2e, #7bc043); }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.export-code { font-family: 'Courier New', monospace; font-size: 12px; background: #fff; border: 1px solid var(--sand-dark);
  border-radius: 4px; padding: 8px; word-break: break-all; margin-top: 8px; display: none; }
.export-code.show { display: block; }

/* ============================ INVENTORY (sheet) ============================ */
.inv-list { display: flex; flex-wrap: wrap; gap: 6px; }
.inv-chip {
  font-size: 12px; background: rgba(255,255,255,0.5); border: 1px solid var(--sand-dark);
  border-radius: 12px; padding: 3px 9px; color: var(--ink);
}

/* ============================ SHOP ============================ */
.shop-greet { font-style: italic; color: #5a4626; margin: 4px 0 12px; }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-row {
  display: grid; grid-template-columns: 32px 1fr auto auto; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.4); border: 1px solid var(--sand-dark); border-radius: 6px; padding: 8px 10px;
}
.shop-row.spell-row { background: rgba(90,60,138,0.18); }
.shop-icon { font-size: 22px; text-align: center; }
.shop-info { font-size: 13px; line-height: 1.3; }
.shop-info small { color: #5a4626; }
.shop-info .own { color: #1d6b2e; font-size: 12px; }
.shop-price { font-weight: bold; color: var(--blood); font-size: 14px; }
.buy-btn { padding: 5px 12px; font-size: 13px; }
.shop-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 14px; }

/* ============================ QUEST LOG ============================ */
.quest-goal { font-size: 14px; line-height: 1.5; }
.quest-list { list-style: none; padding: 0; margin: 12px 0; }
.quest-item {
  background: rgba(255,255,255,0.4); border: 1px solid var(--sand-dark); border-radius: 6px;
  padding: 8px 10px; margin-bottom: 8px; font-size: 14px; line-height: 1.4;
}
.quest-item small { color: #5a4626; }
.quest-item.done { opacity: 0.72; background: rgba(120,160,110,0.28); }
.quest-item .q-mark { font-weight: bold; color: var(--blood); }
.quest-item.done .q-mark { color: #1d6b2e; }
.quest-item .q-icon { font-size: 16px; }
.quest-item .q-status { color: #1d6b2e; font-style: italic; }
.quest-remaining { font-weight: bold; color: var(--blood); }
.save-note { font-size: 13px; color: #1d6b2e; margin-top: 8px; min-height: 18px; }

/* ============================ COMBAT ============================ */
.combat-sheet { max-width: 540px; }
.combat-head { margin-bottom: 8px; }
.foe-name { font-family: var(--font-head); font-size: 20px; color: var(--blood); margin-bottom: 4px; }
.foe-icon { font-size: 22px; }
.bar.foe-hp { height: 16px; }
.bar.foe-hp > i { display: block; height: 100%; background: linear-gradient(90deg, #b52d1f, #e0562b); transition: width 0.3s ease; }
.combat-stage {
  height: 96px; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 90%, rgba(0,0,0,0.12), transparent 70%);
  margin: 6px 0;
}
.foe-sprite { font-size: 62px; animation: foeBob 1.6s ease-in-out infinite; }
@keyframes foeBob { 0%,100% { transform: translateY(0) scale(1);} 50% { transform: translateY(-6px) scale(1.05);} }
.combat-log {
  height: 96px; overflow-y: auto; background: rgba(20,16,12,0.08); border: 1px solid var(--sand-dark);
  border-radius: 6px; padding: 6px 10px; margin: 6px 0; font-size: 13px; line-height: 1.4;
}
.combat-log p { margin: 2px 0; }
.combat-log .log-foe  { color: var(--blood); }
.combat-log .log-you  { color: #1d4d6b; }
.combat-log .log-hint { color: #6a4a1a; font-style: italic; }
.combat-log .log-win  { color: #1d6b2e; font-weight: bold; }
.combat-hero { margin: 6px 0; }
.cv-name { font-family: var(--font-head); font-size: 15px; color: var(--ink); margin-bottom: 4px; }
.cv { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; margin: 3px 0; font-size: 12px; }
.cv .bar { height: 12px; }
.combat-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.combat-actions .btn { flex: 1 1 auto; min-width: 96px; font-size: 14px; padding: 8px 10px; }

/* ============================ VICTORY ============================ */
.victory-panel { text-align: center; max-width: 560px; }
.victory-lead { font-size: 15px; line-height: 1.6; }
.victory-stats {
  display: inline-flex; flex-direction: column; gap: 6px; text-align: left;
  background: rgba(255,255,255,0.45); border: 2px solid var(--sand-dark); border-radius: 8px;
  padding: 14px 22px; margin: 14px 0; font-size: 15px;
}
.victory-foot { font-style: italic; color: #5a4626; }

/* ---- expansion: sheet headings, equipment chips, inn/guild, journal hints ---- */
h4.sh { margin: 12px 0 4px; color: #8a2b1f; font-family: var(--font-head); font-size: 14px; }
.chip-equip {
  background: var(--teal); color: #fff; border: none; border-radius: 8px;
  font-size: 10px; padding: 1px 6px; margin-left: 4px; cursor: pointer; font-family: var(--font-body);
}
.chip-equip:hover { background: #3aa; }
.inv-chip em { color: #1d6b2e; font-style: normal; font-weight: bold; }
.cv-gear { font-size: 13px; opacity: 0.9; }

.inn-vitals { font-size: 13px; color: #5a4626; background: rgba(255,255,255,0.4);
  border: 1px solid var(--sand-dark); border-radius: 6px; padding: 8px 10px; margin: 10px 0; }
.guild-quest { background: rgba(244,197,66,0.22); border: 1px solid var(--sand-dark);
  border-radius: 6px; padding: 10px 12px; font-size: 13.5px; line-height: 1.45; margin-bottom: 10px; }
.guild-note, .save-note { color: #1d6b2e; }

.q-hint { color: #6a4a1a; font-style: italic; }
.quest-item .q-hint { display: inline-block; margin-top: 3px; }

@media (max-width: 520px) {
  .title-main { font-size: 34px; }
  .class-grid { grid-template-columns: 1fr; }
  .controls-hint { font-size: 10px; }
  .shop-row { grid-template-columns: 28px 1fr auto; }
  .shop-row .buy-btn { grid-column: 3; }
}
