:root {
  --bg: #111712;
  --panel: #202a22;
  --panel-2: #2a382d;
  --line: #53624c;
  --gold: #e3b85b;
  --cream: #f4e6ba;
  --text: #e9eee7;
  --muted: #a9b6a8;
  --green: #72b35e;
  --red: #d86455;
  --blue: #5fa3c7;
  --gap: clamp(4px, 0.8vw, 10px);
  --pad: clamp(4px, 0.9vw, 10px);
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(80, 118, 72, .22), transparent 35%),
    linear-gradient(#0e130f, #161d17 55%, #0f140f);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }

#app {
  width: min(1500px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: var(--pad);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) clamp(64px, 13dvh, 104px);
  gap: var(--gap);
  overflow: hidden;
}
.topbar, .chatbar, .viewport-card, .side-panel {
  border: 1px solid #465342;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .3), inset 0 1px rgba(255, 255, 255, .04);
}

.topbar {
  min-height: clamp(48px, 8dvh, 68px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: clamp(5px, 1dvh, 9px) clamp(8px, 1vw, 13px);
  border-radius: 12px 12px 7px 7px;
  background: linear-gradient(180deg, #29352b, #1d271f);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: clamp(34px, 5dvh, 45px);
  height: clamp(34px, 5dvh, 45px);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid #d7ad54;
  border-radius: 10px 2px 10px 2px;
  background: #142118;
  color: var(--gold);
  font: 800 clamp(21px, 3.5dvh, 28px) Georgia, serif;
  transform: rotate(-2deg);
}
.brand h1 {
  margin: 0;
  color: var(--cream);
  font: 700 clamp(17px, 2.8dvh, 23px) Georgia, serif;
  letter-spacing: .4px;
  white-space: nowrap;
}
.brand p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: clamp(8px, 1.35dvh, 11px);
  text-transform: uppercase;
  letter-spacing: 1.6px;
  white-space: nowrap;
}
.status-strip { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }
.status-pill {
  padding: 5px 9px;
  min-width: 72px;
  border: 1px solid #3e4d3e;
  background: #182019;
  border-radius: 7px;
  white-space: nowrap;
}
.status-pill span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .8px; }
.status-pill strong { color: var(--cream); font-size: 12px; }
.top-btn {
  border: 1px solid #64715a;
  border-radius: 6px;
  padding: 7px 10px;
  background: linear-gradient(#43523f, #2c382b);
  color: #fff;
  white-space: nowrap;
}
.top-btn:hover { filter: brightness(1.12); }
.top-btn.danger { border-color: #7c4b43; background: linear-gradient(#673d37, #472924); }

.game-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 23vw, 330px);
  gap: var(--gap);
  overflow: hidden;
}
.viewport-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 7px;
  background: #090d09;
}
#game {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.toast {
  position: absolute;
  top: clamp(48px, 10%, 76px);
  left: 50%;
  transform: translate(-50%, -10px);
  max-width: 76%;
  padding: 7px 11px;
  border: 1px solid #997a35;
  border-radius: 7px;
  background: rgba(27, 25, 16, .94);
  color: #ffe8a0;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  font-size: clamp(10px, 1.6dvh, 13px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hud { position: absolute; pointer-events: none; }
.top-left {
  top: 8px;
  left: 8px;
  width: clamp(190px, 27%, 245px);
  padding: 7px;
  border-radius: 7px;
  background: rgba(12, 17, 12, .8);
  border: 1px solid rgba(130, 146, 118, .45);
}
.bar-row { display: grid; grid-template-columns: 23px 1fr 49px; gap: 6px; align-items: center; font-size: 10px; }
.bar-row + .bar-row { margin-top: 5px; }
.bar { height: 8px; overflow: hidden; border: 1px solid #131713; border-radius: 3px; background: #2a1a18; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #aa3d36, #e66b55); transition: width .2s; }
.bar.xp { background: #1b2024; }
.bar.xp i { background: linear-gradient(90deg, #456d9a, #70b7e1); }
.bar-row b { color: #fff3cc; text-align: right; }
.bottom-center {
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 5px 10px;
  border-radius: 18px;
  background: rgba(11, 16, 11, .81);
  color: #e8eadf;
  border: 1px solid rgba(144, 159, 129, .42);
  font-size: clamp(9px, 1.5dvh, 12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-panel {
  min-height: 0;
  border-radius: 7px;
  overflow: hidden;
  background: linear-gradient(180deg, #263128, #1b241d);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); background: #141b16; border-bottom: 1px solid #4b5949; }
.tab {
  min-width: 0;
  border: 0;
  border-right: 1px solid #344035;
  padding: clamp(7px, 1.4dvh, 11px) 2px;
  color: #a9b4a6;
  background: transparent;
  font-size: clamp(9px, 1.45dvh, 12px);
}
.tab:last-child { border-right: 0; }
.tab.active { color: #ffeab1; background: linear-gradient(#344335, #27342a); box-shadow: inset 0 -2px var(--gold); }
.panel {
  display: none;
  min-height: 0;
  height: 100%;
  padding: clamp(7px, 1.35dvh, 13px);
  overflow: hidden;
}
.panel.active { display: block; }
.panel h2 { margin: 0; color: var(--cream); font: 700 clamp(15px, 2.3dvh, 19px) Georgia, serif; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: clamp(5px, 1dvh, 10px); color: var(--muted); font-size: clamp(9px, 1.4dvh, 12px); }

.inventory-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: clamp(3px, .55dvh, 6px); }
.slot {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid #566453;
  border-radius: 5px;
  background: radial-gradient(circle at 40% 30%, #344238, #1b241d 75%);
  display: grid;
  place-items: center;
  color: #fff;
  user-select: none;
}
.slot:hover { border-color: #c3a755; filter: brightness(1.1); }
.slot.selected { outline: 2px solid var(--gold); }
.slot .icon { font-size: clamp(18px, 3.5dvh, 25px); filter: drop-shadow(0 2px 1px rgba(0,0,0,.5)); }
.slot .qty { position: absolute; right: 3px; bottom: 2px; font-size: 9px; color: #fff0a6; text-shadow: 1px 1px #000; }
.slot .name { position: absolute; left: 3px; right: 3px; top: 2px; font-size: 7px; color: #d4dccf; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-details {
  margin-top: clamp(5px, 1dvh, 10px);
  min-height: 54px;
  max-height: clamp(54px, 15dvh, 86px);
  padding: clamp(6px, 1dvh, 9px);
  border: 1px solid #445143;
  border-radius: 6px;
  background: rgba(13, 18, 14, .45);
  color: #c8d1c5;
  font-size: clamp(9px, 1.45dvh, 12px);
  line-height: 1.3;
  overflow: hidden;
}
.item-action {
  margin-top: 5px;
  border: 1px solid #7f6f3c;
  border-radius: 5px;
  padding: 4px 8px;
  background: #504628;
  color: #fff1b8;
}

.skills-list { display: grid; gap: clamp(3px, .75dvh, 7px); }
.skill-row { padding: clamp(4px, .85dvh, 8px); border: 1px solid #435143; border-radius: 6px; background: rgba(10, 16, 11, .35); }
.skill-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.skill-name { color: #f2e3b2; font-weight: 700; font-size: clamp(10px, 1.55dvh, 13px); }
.skill-level { color: #d6dbd3; font-size: clamp(9px, 1.4dvh, 12px); }
.skill-bar { height: 5px; border-radius: 4px; overflow: hidden; background: #121812; }
.skill-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8b732f, #e5be5f); }
.skill-xp { margin-top: 3px; color: #91a090; font-size: clamp(8px, 1.2dvh, 10px); }

.quest-card { padding: clamp(7px, 1.3dvh, 11px); border: 1px solid #4c5b49; border-radius: 7px; background: #172019; }
.quest-card h3 { margin: 0 0 4px; color: #f0ddb1; font: 700 clamp(14px, 2dvh, 16px) Georgia, serif; }
.quest-card p { margin: 0 0 6px; color: #b9c3b6; font-size: clamp(9px, 1.45dvh, 12px); line-height: 1.35; }
.objective { display: flex; justify-content: space-between; padding: 3px 0; color: #d6dbd2; font-size: clamp(9px, 1.35dvh, 11px); border-top: 1px dashed #3b463a; }
.objective.done { color: #74bb68; }
.quest-state { margin-top: 6px; color: #d4b75b; font-size: clamp(8px, 1.25dvh, 10px); text-transform: uppercase; letter-spacing: .8px; }

.shop-balance {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #ffe298;
}
.shop-grid { display: grid; gap: clamp(4px, .8dvh, 7px); }
.shop-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: clamp(5px, .9dvh, 8px);
  border: 1px solid #4c5948;
  border-radius: 6px;
  background: rgba(12, 18, 13, .42);
}
.shop-icon { font-size: clamp(20px, 3.4dvh, 28px); }
.shop-copy { min-width: 0; }
.shop-copy b { display: block; color: #f2e2b1; font-size: clamp(10px, 1.55dvh, 13px); }
.shop-copy span { display: block; margin-top: 2px; color: #9eab9b; font-size: clamp(8px, 1.25dvh, 10px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.buy-btn, .sell-btn {
  border: 1px solid #80703f;
  border-radius: 5px;
  padding: 5px 7px;
  background: linear-gradient(#5d522d, #423a20);
  color: #fff1b8;
  font-size: clamp(9px, 1.35dvh, 11px);
  white-space: nowrap;
}
.buy-btn:disabled, .sell-btn:disabled { cursor: default; opacity: .45; filter: grayscale(.5); }
.shop-footer { margin-top: clamp(5px, 1dvh, 9px); padding-top: clamp(5px, 1dvh, 9px); border-top: 1px solid #3e493d; }
.sell-btn { width: 100%; background: linear-gradient(#405140, #2b382c); border-color: #5c705b; }
.shop-note { margin: 5px 0 0; color: #8f9c8c; font-size: clamp(8px, 1.2dvh, 10px); text-align: center; }

.help-card { margin-top: clamp(6px, 1dvh, 10px); padding: clamp(7px, 1.2dvh, 11px); border: 1px solid #465446; border-radius: 7px; background: #171f19; }
.help-card p { margin: 0 0 6px; color: #c6cec3; font-size: clamp(9px, 1.45dvh, 12px); line-height: 1.35; }
.help-card p:last-child { margin: 0; }
.legend { margin-top: clamp(7px, 1.2dvh, 12px); display: grid; grid-template-columns: 1fr 1fr; gap: 6px; color: #c9d0c6; font-size: clamp(9px, 1.4dvh, 12px); }
.dot { width: 9px; height: 9px; display: inline-block; margin-right: 5px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.1); }
.dot.tree { background: #397441; }.dot.rock { background: #899092; }.dot.fish { background: #4ba0bd; }.dot.enemy { background: #b44f42; }.dot.npc { background: #d4b45d; }

.chatbar {
  min-height: 0;
  border-radius: 7px 7px 12px 12px;
  overflow: hidden;
  background: #141b16;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}
.chat-log { min-height: 0; overflow: hidden; padding: 5px 9px; color: #c9d3c6; font-size: clamp(9px, 1.45dvh, 12px); line-height: 1.35; }
.chat-line.system { color: #e2c66d; }
.chat-line.combat { color: #e78175; }
.chat-line.skill { color: #70b7db; }
.chat-line .speaker { color: #f6e4ae; font-weight: 700; }
.chat-form { display: grid; grid-template-columns: 1fr auto; border-top: 1px solid #374338; }
.chat-form input { min-width: 0; border: 0; padding: 6px 9px; background: #1c251e; color: #f3f4f0; outline: none; font-size: clamp(9px, 1.45dvh, 12px); }
.chat-form button { border: 0; border-left: 1px solid #435043; padding: 0 14px; background: #354334; color: #efe0ad; font-size: clamp(9px, 1.45dvh, 12px); }

.rotate-device {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  place-items: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 25%, #26352a, #0e140f 72%);
  color: var(--cream);
  text-align: center;
}
.rotate-card { max-width: 330px; }
.rotate-icon { display: block; margin-bottom: 13px; font-size: 54px; }
.rotate-card h2 { margin: 0 0 8px; font: 700 25px Georgia, serif; }
.rotate-card p { margin: 0; color: #bcc7ba; font-size: 14px; line-height: 1.45; }

@media (max-width: 900px) and (orientation: portrait) {
  .rotate-device { display: grid; }
}

@media (max-width: 900px) and (orientation: landscape) {
  :root { --gap: 4px; --pad: 4px; }
  #app { grid-template-rows: 40px minmax(0, 1fr) 50px; }
  .topbar { min-height: 40px; height: 40px; padding: 3px 6px; border-radius: 7px; }
  .brand { gap: 6px; }
  .brand-mark { width: 30px; height: 30px; font-size: 19px; border-width: 1px; }
  .brand h1 { font-size: 15px; }
  .brand p { display: none; }
  .status-strip { gap: 4px; }
  .status-pill { min-width: 59px; padding: 3px 6px; }
  .status-pill.world-pill { display: none; }
  .status-pill span { font-size: 7px; }
  .status-pill strong { font-size: 10px; }
  .top-btn { padding: 5px 7px; font-size: 9px; }
  .game-shell { grid-template-columns: minmax(0, 1fr) clamp(215px, 31vw, 255px); }
  .tab { padding: 6px 1px; font-size: 8px; }
  .panel { padding: 5px; }
  .panel h2 { font-size: 13px; }
  .panel-heading { margin-bottom: 4px; font-size: 8px; }
  .inventory-grid { gap: 2px; }
  .slot .name { display: none; }
  .slot .icon { font-size: min(20px, 5dvh); }
  .item-details { margin-top: 4px; min-height: 45px; max-height: 50px; padding: 4px 5px; font-size: 8px; line-height: 1.2; }
  .item-action { margin-top: 3px; padding: 2px 6px; font-size: 8px; }
  .skills-list { gap: 2px; }
  .skill-row { padding: 3px 4px; }
  .skill-head { margin-bottom: 2px; }
  .skill-name, .skill-level { font-size: 8px; }
  .skill-xp { margin-top: 1px; font-size: 7px; }
  .quest-card { padding: 5px; }
  .quest-card h3 { font-size: 12px; }
  .quest-card p, .objective { font-size: 8px; }
  .quest-state { font-size: 7px; }
  .shop-grid { gap: 3px; }
  .shop-item { gap: 5px; padding: 3px 4px; }
  .shop-icon { font-size: 18px; }
  .shop-copy b { font-size: 8px; }
  .shop-copy span { font-size: 7px; }
  .buy-btn, .sell-btn { padding: 3px 5px; font-size: 8px; }
  .shop-footer { margin-top: 3px; padding-top: 3px; }
  .shop-note { margin-top: 2px; font-size: 7px; }
  .help-card { margin-top: 4px; padding: 5px; }
  .help-card p, .legend { font-size: 8px; }
  .help-card p { margin-bottom: 3px; }
  .legend { margin-top: 5px; gap: 3px; }
  .top-left { top: 5px; left: 5px; width: 178px; padding: 4px; }
  .bar-row { grid-template-columns: 18px 1fr 42px; gap: 4px; font-size: 8px; }
  .bar-row + .bar-row { margin-top: 3px; }
  .bar { height: 6px; }
  .bottom-center { bottom: 4px; padding: 3px 7px; font-size: 8px; }
  .toast { top: 38px; padding: 4px 7px; font-size: 8px; }
  .chat-log { padding: 3px 7px; font-size: 8px; line-height: 1.2; }
  .chat-form input { padding: 3px 7px; font-size: 8px; }
  .chat-form button { padding: 0 10px; font-size: 8px; }
}

@media (min-width: 901px) and (max-height: 700px) {
  #app { grid-template-rows: auto minmax(0, 1fr) 70px; }
  .topbar { min-height: 48px; }
  .brand p { display: none; }
  .panel { padding: 8px; }
  .item-details { max-height: 62px; }
}
