/* ============================================================
   ROYAL REVENUE SERVICE — flat modern UI over pixel-fantasy
   UI sprites: Complete UI Essential Pack (CC BY 4.0)
   ============================================================ */

:root {
  --ink: #2b2f36;
  --ink-soft: #5b6470;
  --paper: #fffdf4;
  --bg: #d8dde3;
  --accent: #2f7fe0;
  --gold: #c5861e;
  --good: #2e9e3a;
  --bad: #d23b34;
  --font: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

.px { image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }

.screen { position: absolute; inset: 0; }

/* ---------- shared sprite components ---------- */

.btn {
  border: 10px solid transparent;
  border-image: url("assets/ui/UI_Flat_Button01a_1.png") 10 fill stretch;
  image-rendering: pixelated;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 0 6px 2px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.05s;
}
.btn:hover  { border-image-source: url("assets/ui/UI_Flat_Button01a_2.png"); }
.btn:active { border-image-source: url("assets/ui/UI_Flat_Button01a_3.png"); transform: translateY(2px); }
.btn:disabled {
  border-image-source: url("assets/ui/UI_Flat_Button01a_4.png");
  color: #9aa1ab; cursor: not-allowed; transform: none;
}

.btn-primary {
  border-image: url("assets/ui/UI_Flat_Frame02a.png") 14 fill stretch;
  border-width: 10px;
  color: #fff;
}
.btn-primary:hover  { filter: brightness(1.1); }
.btn-primary:active { filter: brightness(0.92); }
.btn-primary:disabled { filter: grayscale(0.7) brightness(1.05); color: #eef2f7; }

.btn-danger { color: var(--bad); }
.btn-big   { font-size: 18px; min-height: 52px; min-width: 280px; }
.btn-small { font-size: 12px; min-height: 32px; }
.btn-icon  { min-width: 38px; font-size: 16px; padding: 0 2px 2px; }

.panel {
  border: 14px solid transparent;
  border-image: url("assets/ui/UI_Flat_Frame01a.png") 18 fill stretch;
  image-rendering: pixelated;
}

.banner {
  border: 8px solid transparent;
  border-image: url("assets/ui/UI_Flat_Banner03a.png") 8 fill stretch;
  image-rendering: pixelated;
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.18em;
  color: var(--ink);
  padding: 2px 10px 6px;
  margin: -4px auto 8px;
  display: block;
  width: fit-content;
  min-width: 180px;
}

.bar {
  border: 3px solid transparent;
  border-image: url("assets/ui/UI_Flat_Bar04a.png") 3 fill stretch;
  image-rendering: pixelated;
  height: 16px;
  width: 140px;
  position: relative;
  overflow: hidden;
}
.bar-fill {
  position: absolute; inset: 0;
  width: 50%;
  transition: width 0.25s ease, background-color 0.25s;
}
.fill-rep { background: rgb(20,238,20); }
.fill-day { background: var(--accent); }
.tiny-bar { height: 10px; width: 120px; margin-top: 4px; }

.toggle {
  width: 40px; height: 40px;
  border: none; cursor: pointer;
  background: url("assets/ui/UI_Flat_ToggleOff01a.png") center / contain no-repeat;
  image-rendering: pixelated;
}
.toggle.on { background-image: url("assets/ui/UI_Flat_ToggleOn01a.png"); }

/* ============================================================
   TITLE SCREEN
   ============================================================ */

#screen-title {
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.25) 0 24px, rgba(255,255,255,0) 24px 48px),
    var(--bg);
}

.title-box {
  text-align: center;
  border: 18px solid transparent;
  border-image: url("assets/ui/UI_Flat_Frame01a.png") 18 fill stretch;
  image-rendering: pixelated;
  padding: 28px 56px 20px;
  max-width: 720px;
}

.title-crest img { width: 64px; height: 64px; }
.title-h1 { font-size: 42px; letter-spacing: 0.1em; margin: 6px 0 2px; }
.title-sub { color: var(--ink-soft); font-size: 14px; letter-spacing: 0.2em; text-transform: uppercase; }
.title-tagline {
  margin: 16px 0 4px; font-size: 17px; font-style: italic; color: var(--ink-soft);
  min-height: 24px;
}

.title-queue {
  display: flex; justify-content: center; align-items: flex-end; gap: 10px;
  min-height: 110px; margin: 10px 0;
}
.title-queue img { width: 96px; height: 96px; image-rendering: pixelated; }

.title-buttons { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-bottom: 10px; }
.title-small-buttons { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.title-foot { font-size: 11px; color: #9aa1ab; }

/* ============================================================
   GAME LAYOUT
   ============================================================ */

#screen-game { display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px;
  background: #eef1f4;
  border-bottom: 3px solid #c3cad2;
  gap: 16px;
  flex: 0 0 auto;
}
.topbar-group { display: flex; align-items: center; gap: 14px; }
.tb-title { font-weight: 800; letter-spacing: 0.12em; font-size: 13px; color: var(--ink-soft); }
.tb-day { font-size: 13px; }
.hud-gold { display: flex; align-items: center; gap: 8px; font-size: 26px; font-weight: 800; color: var(--gold); }
.coin-icon { width: 28px; height: 28px; }
.hud-gold.bump { animation: goldbump 0.18s; }
@keyframes goldbump { 50% { transform: scale(1.18); } }
.hud-rate { font-size: 12px; color: var(--ink-soft); }
.hud-rep { display: flex; align-items: center; gap: 8px; }
.rep-label { font-size: 11px; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.1em; }
.hud-streak { font-size: 12px; color: var(--ink-soft); min-width: 70px; text-align: right; }
.hud-streak.hot { color: var(--good); font-weight: 700; }

#game-main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

/* ---------- rules panel ---------- */

#rules-panel { padding: 4px 8px; overflow-y: auto; }
.rules-section-label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-soft); margin: 10px 4px 4px;
}
.edict-label { color: var(--bad); }
.edict-note { font-weight: 400; text-transform: none; letter-spacing: 0; }
.rules-list { list-style: none; }
.rules-list li {
  font-size: 13px; line-height: 1.35;
  padding: 6px 8px; margin: 4px 2px;
  background: rgba(255,255,255,0.55);
  border-left: 4px solid #b9c1ca;
}
.rules-list.edicts li { border-left-color: var(--bad); background: #fdf0ef; animation: edictin 0.4s; }
.rules-list li.waived { text-decoration: line-through; color: #9aa1ab; }
.rules-list li .rule-no { font-weight: 800; color: var(--ink-soft); margin-right: 4px; }
.rules-list.edicts li .rule-no { color: var(--bad); }
@keyframes edictin { from { transform: translateX(-12px); opacity: 0; } }
.rules-foot { font-size: 11px; color: #9aa1ab; font-style: italic; margin: 12px 4px 6px; }

/* ---------- desk ---------- */

#desk { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#inbox-row { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 6px; }
#inbox-stack { display: flex; gap: 3px; align-items: flex-end; }
.inbox-doc {
  width: 18px; height: 24px;
  border: 4px solid transparent;
  border-image: url("assets/ui/UI_Flat_InputField01a.png") 6 fill stretch;
  image-rendering: pixelated;
}
#inbox-count { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
#inbox-count.full { color: var(--bad); }

#doc-area { flex: 1 1 auto; position: relative; min-height: 0; display: flex; align-items: stretch; justify-content: center; padding: 6px 0; }

.doc {
  width: min(640px, 100%);
  border: 16px solid transparent;
  border-image: url("assets/ui/UI_Flat_InputField01a.png") 10 fill stretch;
  image-rendering: pixelated;
  padding: 6px 18px 14px;
  position: relative;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.doc.slide-in  { animation: docin 0.28s ease-out; }
.doc.slide-out-l { animation: docoutL 0.26s ease-in forwards; }
.doc.slide-out-r { animation: docoutR 0.26s ease-in forwards; }
@keyframes docin   { from { transform: translateY(-40px); opacity: 0; } }
@keyframes docoutL { to { transform: translateX(-120%) rotate(-4deg); opacity: 0; } }
@keyframes docoutR { to { transform: translateX(120%) rotate(4deg); opacity: 0; } }

.doc-head { border-bottom: 2px dashed #d9d2b8; padding-bottom: 6px; margin-bottom: 10px; }
.doc-ref { font-size: 11px; letter-spacing: 0.2em; color: #b0a87f; font-weight: 700; }
.doc-title { font-size: 21px; font-weight: 800; }

.doc-body-grid { display: grid; grid-template-columns: 168px 1fr; gap: 16px; align-items: start; }

.photo-slot {
  width: 168px; height: 168px;
  border: 12px solid transparent;
  border-image: url("assets/ui/UI_Flat_FrameSlot01a.png") 10 fill stretch;
  image-rendering: pixelated;
  display: flex; align-items: center; justify-content: center;
  background-clip: padding-box;
}
.photo-slot img { width: 144px; height: 144px; image-rendering: pixelated; object-fit: contain; }

.doc-fields { font-size: 14px; line-height: 1.5; }
.doc-fields .f-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid #f0ead2; }
.doc-fields .f-key { color: var(--ink-soft); white-space: nowrap; }
.doc-fields .f-val { font-weight: 700; text-align: right; }
.doc-fields .f-val.violation-hint { color: var(--bad); text-decoration: underline wavy var(--bad); }

.doc-flavor {
  margin-top: 12px; font-size: 14px; line-height: 1.5;
  color: #4a4636; font-style: italic;
  border-top: 2px dashed #d9d2b8; padding-top: 8px;
}

.doc-stamp {
  position: absolute; top: 38%; left: 50%;
  font-size: 54px; font-weight: 900; letter-spacing: 0.1em;
  padding: 6px 26px;
  border: 6px solid currentColor; border-radius: 8px;
  transform: translate(-50%, -50%) rotate(-14deg) scale(3);
  opacity: 0;
  pointer-events: none;
}
.doc-stamp.show { animation: stampthunk 0.22s ease-in forwards; }
.doc-stamp.approved { color: var(--good); }
.doc-stamp.denied   { color: var(--bad); }
@keyframes stampthunk {
  0%   { transform: translate(-50%, -50%) rotate(-14deg) scale(3); opacity: 0; }
  60%  { transform: translate(-50%, -50%) rotate(-14deg) scale(0.92); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-14deg) scale(1); opacity: 0.92; }
}

.doc-empty {
  align-self: center; text-align: center; color: var(--ink-soft); font-size: 18px;
}
.doc-empty .small { font-size: 13px; margin-top: 6px; color: #9aa1ab; }

.feedback {
  height: 26px; text-align: center; font-size: 14px; font-weight: 700;
  padding-top: 2px;
}
.feedback.good { color: var(--good); }
.feedback.bad  { color: var(--bad); }

#stamp-row { display: flex; gap: 18px; justify-content: center; padding: 8px 0 2px; flex: 0 0 auto; }
.stamp-btn { font-size: 20px; min-height: 60px; min-width: 220px; font-weight: 900; }
.stamp-icon { width: 28px; height: 24px; }
.stamp-approve { color: var(--good); }
.stamp-deny   { color: var(--bad); }
.key-hint { font-size: 12px; color: #9aa1ab; font-weight: 400; }

/* ---------- bureau ---------- */

#bureau-panel { padding: 4px 8px; display: flex; flex-direction: column; overflow-y: auto; }

.clerk-status {
  font-size: 12px; color: var(--ink-soft);
  background: rgba(255,255,255,0.55); padding: 6px 8px; margin: 0 2px 6px;
  border-left: 4px solid var(--accent);
  min-height: 30px;
}

.upgrade {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  align-items: center;
  padding: 7px 8px; margin: 5px 2px;
  background: rgba(255,255,255,0.55);
  border-left: 4px solid #b9c1ca;
}
.upgrade.affordable { border-left-color: var(--good); }
.upgrade.maxed { opacity: 0.6; }
.up-name { font-size: 13px; font-weight: 800; }
.up-name .up-lvl { font-weight: 400; color: var(--ink-soft); font-size: 12px; }
.up-desc { font-size: 11.5px; color: var(--ink-soft); grid-column: 1; line-height: 1.3; }
.up-buy { grid-row: 1 / span 2; min-width: 86px; min-height: 34px; font-size: 12px; }
.up-buy img { width: 14px; height: 14px; }

#prestige-box { margin-top: auto; padding: 8px 2px 4px; }
.prestige-info { font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; line-height: 1.4; }
.btn-prestige { width: 100%; color: #8a5a18; font-weight: 900; }

/* ---------- ticker ---------- */

#ticker-bar {
  flex: 0 0 auto; height: 30px; overflow: hidden;
  background: #2b2f36; color: #cfd6de;
  display: flex; align-items: center;
  font-size: 13px;
}
#ticker-text { white-space: nowrap; padding-left: 100%; animation: tick 28s linear infinite; }
@keyframes tick { to { transform: translateX(-200%); } }

/* ---------- fx ---------- */

#fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.float-gold {
  position: absolute; font-weight: 900; font-size: 20px; color: var(--gold);
  text-shadow: 0 1px 0 #fff;
  animation: floatup 1s ease-out forwards;
}
.float-rep { color: var(--bad); font-size: 16px; }
@keyframes floatup { to { transform: translateY(-70px); opacity: 0; } }

.shake { animation: shake 0.3s; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px,2px); }
  40% { transform: translate(5px,-3px); }
  60% { transform: translate(-4px,-2px); }
  80% { transform: translate(3px,2px); }
}

/* ---------- overlays / modals ---------- */

.overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(43,47,54,0.55);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg);
  border: 16px solid transparent;
  border-image: url("assets/ui/UI_Flat_Frame01a.png") 18 fill stretch;
  image-rendering: pixelated;
  width: min(520px, 92vw);
  max-height: 86vh; overflow-y: auto;
  padding: 10px 22px 18px;
  text-align: center;
}
.banner-modal { margin-bottom: 14px; }
.banner-danger { color: var(--bad); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px; font-size: 15px; text-align: left;
  border-bottom: 1px solid #c3cad2;
}
.settings-row small { color: var(--ink-soft); }
.modal-close { margin-top: 16px; min-width: 140px; }
.modal-btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.credits-body { font-size: 14px; line-height: 1.55; }
.credits-body p { margin: 10px 0; }
.credits-body table { margin: 0 auto; font-size: 14px; border-collapse: collapse; }
.credits-body td { padding: 3px 10px; text-align: left; }
.credits-body td.num { text-align: right; font-weight: 700; }

/* narrow screens: stack panels */
@media (max-width: 1080px) {
  #game-main { grid-template-columns: 240px 1fr 260px; }
  .doc-body-grid { grid-template-columns: 120px 1fr; }
  .photo-slot { width: 120px; height: 120px; }
  .photo-slot img { width: 96px; height: 96px; }
}
