:root {
  color-scheme: dark;
  --paper: #f3ead8;
  --panel: rgba(25, 36, 33, 0.78);
  --panel-solid: #24342f;
  --line: rgba(243, 234, 216, 0.18);
  --gold: #d7a84b;
  --muted: #b9c3b5;
  --text: #f7f0df;
  --danger: #d96b5f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #17201e;
  color: var(--text);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

button {
  border: 1px solid rgba(247, 240, 223, 0.24);
  border-radius: 8px;
  background: rgba(49, 72, 65, 0.9);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  min-height: 36px;
  touch-action: manipulation;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

button:hover {
  background: rgba(61, 93, 83, 0.96);
  border-color: rgba(247, 240, 223, 0.4);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.hidden-control {
  display: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.05rem, 1.8vw, 1.65rem);
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

h2 {
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.app {
  height: 100dvh;
  min-height: 540px;
  position: relative;
  width: 100vw;
}

canvas {
  background: #202b29;
  display: block;
  height: 100%;
  inset: 0;
  position: absolute;
  width: 100%;
}

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

.is-game-over .hud {
  display: none;
}

.start-panel {
  align-items: center;
  background:
    linear-gradient(rgba(10, 14, 13, 0.62), rgba(10, 14, 13, 0.78)),
    radial-gradient(circle at 30% 18%, rgba(215, 168, 75, 0.18), transparent 32%),
    rgba(18, 26, 24, 0.92);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 24px;
  pointer-events: auto;
  position: absolute;
  z-index: 20;
}

.start-panel.is-hidden {
  display: none;
}

.start-card {
  background: rgba(25, 36, 33, 0.9);
  border: 1px solid rgba(215, 168, 75, 0.4);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
  max-height: calc(100vh - 48px);
  max-width: min(920px, calc(100vw - 40px));
  overflow: auto;
  padding: 18px;
  width: 100%;
  backdrop-filter: blur(14px);
}

.start-card h2 {
  color: var(--paper);
  font-size: 1.55rem;
  line-height: 1.15;
  margin: 0 0 8px;
}

.start-eyebrow {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.start-copy {
  color: #d9dfd0;
  font-size: 0.86rem;
  line-height: 1.55;
  margin-bottom: 14px;
  max-width: 720px;
}

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

.character-card {
  align-content: start;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.14);
  border-radius: 8px;
  color: #d9dfd0;
  cursor: pointer;
  display: grid;
  gap: 8px;
  min-height: 250px;
  padding: 9px;
  text-align: left;
}

.character-card:hover,
.character-card:focus-visible {
  border-color: rgba(215, 168, 75, 0.84);
  box-shadow: inset 0 0 0 1px rgba(215, 168, 75, 0.35);
  outline: none;
}

.character-card img {
  align-self: center;
  height: 96px;
  justify-self: center;
  object-fit: contain;
  width: 92px;
}

.character-card strong {
  color: var(--paper);
  font-size: 0.86rem;
}

.character-card small {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 800;
}

.character-card span {
  color: #d9dfd0;
  font-size: 0.7rem;
  line-height: 1.45;
}

.tutorial-step {
  display: none;
  max-width: min(620px, calc(100vw - 40px));
}

.tutorial-step.is-open {
  display: block;
}

.character-step.is-hidden {
  display: none;
}

.tutorial-list {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.tutorial-copy {
  margin: 14px 0;
}

.tutorial-copy p {
  color: #d9dfd0;
  font-size: 0.82rem;
  line-height: 1.75;
  margin: 0;
}

.tutorial-copy p + p {
  margin-top: 8px;
}

.tutorial-list div {
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 8px;
}

.tutorial-list strong {
  color: var(--gold);
}

.tutorial-list span {
  color: #d9dfd0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.tutorial-step button {
  width: 100%;
}

.topbar,
.floating-panel,
.demon-panel,
.gm-secret,
.command-bar {
  pointer-events: auto;
}

.topbar {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  left: 14px;
  position: absolute;
  right: 14px;
  top: 12px;
}

.eyebrow {
  align-items: center;
  color: var(--gold);
  display: flex;
  font-size: 0.66rem;
  gap: 7px;
  letter-spacing: 0.02em;
  margin: 0 0 4px;
  text-transform: uppercase;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

.version-pill {
  background: rgba(247, 240, 223, 0.14);
  border: 1px solid rgba(243, 234, 216, 0.22);
  border-radius: 999px;
  color: #f7f0df;
  font-size: 0.58rem;
  line-height: 1;
  padding: 3px 6px;
  text-transform: none;
}

.clock {
  align-items: flex-end;
  background: rgba(25, 36, 33, 0.62);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 9px;
  backdrop-filter: blur(10px);
}

.clock span {
  color: var(--muted);
  font-size: 0.66rem;
}

.clock strong {
  color: var(--gold);
  font-size: 0.82rem;
}

.floating-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
  font-size: 0.78rem;
  padding: 8px;
  padding-right: 30px;
  position: absolute;
  width: min(214px, calc(100vw - 28px));
  backdrop-filter: blur(12px);
  transition:
    transform 180ms ease,
    opacity 180ms ease;
  z-index: 5;
}

.floating-panel h2 {
  cursor: pointer;
  font-size: 0.74rem;
  margin-bottom: 5px;
  outline: none;
}

.panel-close {
  align-items: center;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.16);
  border-radius: 8px;
  color: var(--paper);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 900;
  height: 22px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: absolute;
  right: 6px;
  top: 6px;
  width: 22px;
}

.panel-close:hover,
.panel-close:focus-visible {
  background: rgba(215, 168, 75, 0.2);
  border-color: rgba(215, 168, 75, 0.6);
  outline: none;
}

.panel-tab {
  background: rgba(25, 36, 33, 0.9);
  border: 1px solid rgba(247, 240, 223, 0.24);
  border-radius: 8px;
  color: var(--paper);
  display: none;
  font-size: 0.72rem;
  font-weight: 700;
  min-height: 28px;
  min-width: 44px;
  padding: 5px 8px;
  position: absolute;
  text-align: center;
  white-space: nowrap;
}

.floating-panel.is-collapsed {
  opacity: 0.84;
  overflow: visible;
}

.floating-panel.is-collapsed .panel-tab {
  display: block;
}

.floating-panel.is-collapsed .panel-close {
  display: none;
}

.dock-left.is-collapsed {
  transform: translateX(calc(-100% - 10px));
}

.dock-left.is-collapsed .panel-tab {
  right: -66px;
  top: var(--tab-offset, 10px);
}

.dock-right.is-collapsed {
  transform: translateX(calc(100% + 10px));
}

.craft-panel.dock-right.is-collapsed {
  transform: translateX(calc(100% + 240px));
}

.dock-right.is-collapsed .panel-tab {
  left: -66px;
  top: var(--tab-offset, 10px);
}

.dock-top.is-collapsed {
  transform: translate(-50%, calc(-100% - 10px));
}

.dock-top.is-collapsed .panel-tab {
  bottom: -38px;
  left: 50%;
  transform: translateX(-50%);
}

.status-panel {
  left: 10px;
  top: 70px;
}

.inventory-panel {
  bottom: 62px;
  left: 10px;
  max-height: min(520px, calc(100dvh - 190px));
  overflow: auto;
}

.storage-popup {
  background: rgba(23, 32, 30, 0.94);
  border: 1px solid rgba(215, 168, 75, 0.48);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  color: var(--paper);
  display: none;
  max-height: min(316px, calc(100dvh - 144px));
  overflow: auto;
  padding: 8px;
  pointer-events: auto;
  position: fixed;
  z-index: 8;
}

.storage-popup.is-open {
  display: grid;
  gap: 7px;
}

.storage-popup__header,
.storage-popup__summary {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.storage-popup__header strong {
  color: var(--gold);
  font-size: 0.78rem;
}

.storage-popup__header button {
  min-height: 24px;
  padding: 2px 8px;
}

.storage-popup__content,
.storage-popup__block {
  display: grid;
  gap: 6px;
}

.storage-popup__summary span {
  color: var(--muted);
  font-size: 0.64rem;
}

.storage-popup__summary button {
  font-size: 0.68rem;
  font-weight: 800;
  min-height: 30px;
  padding: 4px 8px;
}

.storage-popup__grid {
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.storage-popup__item {
  align-items: center;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  color: inherit;
  min-height: 44px;
  padding: 4px;
  text-align: center;
}

.storage-popup__item.is-selected {
  background: rgba(215, 168, 75, 0.18);
  border-color: rgba(215, 168, 75, 0.78);
}

.storage-popup__item > span:not(.inventory-tooltip):not(.inventory-icon__fallback) {
  color: var(--muted);
  font-size: 0.62rem;
  min-width: 0;
}

.route-panel {
  right: 10px;
  top: 70px;
  max-height: min(430px, calc(100dvh - 188px));
  overflow: auto;
}

.castle-panel {
  display: none;
  right: 10px;
  top: 262px;
}

.online-panel {
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  width: min(248px, calc(100vw - 28px));
}

.craft-panel {
  display: none;
}

.workshop-popup {
  background: rgba(23, 32, 30, 0.94);
  border: 1px solid rgba(183, 109, 59, 0.58);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  color: var(--paper);
  display: none;
  max-height: min(420px, calc(100dvh - 144px));
  overflow: hidden;
  padding: 10px;
  pointer-events: auto;
  position: fixed;
  touch-action: pan-y;
  z-index: 8;
}

.workshop-popup.is-open {
  display: grid;
  gap: 9px;
  grid-template-rows: auto minmax(0, 1fr);
}

.workshop-popup__content {
  display: grid;
  gap: 8px;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.workshop-popup__summary {
  line-height: 1.35;
}

.workshop-popup__tabs {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.workshop-tab {
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(247, 240, 223, 0.18);
  border-radius: 7px;
  color: var(--paper);
  cursor: pointer;
  min-height: 34px;
  padding: 7px 6px;
}

.workshop-tab.active {
  background: rgba(183, 109, 59, 0.32);
  border-color: rgba(215, 168, 75, 0.72);
  color: #fff7e5;
}

.workshop-craft-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.workshop-craft-icon {
  align-items: center;
  aspect-ratio: 1;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  display: grid;
  justify-items: center;
  min-height: 48px;
  padding: 4px;
  position: relative;
}

.workshop-craft-icon.is-selected {
  background: rgba(215, 168, 75, 0.18);
  border-color: rgba(215, 168, 75, 0.78);
}

.workshop-craft-icon:hover .inventory-tooltip,
.workshop-craft-icon:focus-visible .inventory-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.workshop-detail {
  background: rgba(247, 240, 223, 0.07);
  border: 1px solid rgba(247, 240, 223, 0.13);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 9px;
}

.workshop-detail__main {
  align-items: center;
  display: grid;
  gap: 9px;
  grid-template-columns: 48px minmax(0, 1fr);
}

.workshop-detail__main strong {
  color: var(--paper);
  display: block;
  font-size: 0.9rem;
}

.workshop-detail__main span,
.workshop-detail p {
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.45;
}

.workshop-detail p {
  margin: 0;
}

.workshop-detail__icon {
  align-items: center;
  aspect-ratio: 1;
  background: rgba(23, 32, 30, 0.32);
  border: 1px solid rgba(247, 240, 223, 0.12);
  border-radius: 8px;
  display: grid;
  justify-items: center;
}

.workshop-detail__materials {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.workshop-material {
  align-items: center;
  background: rgba(23, 32, 30, 0.3);
  border: 1px solid rgba(247, 240, 223, 0.12);
  border-radius: 8px;
  color: var(--paper);
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: 58px;
  padding: 5px 3px;
}

.workshop-material.is-missing {
  border-color: rgba(214, 111, 162, 0.58);
  color: #ffd9e4;
}

.workshop-material .inventory-icon__image,
.workshop-material .inventory-icon__fallback {
  height: 28px;
  width: 28px;
}

.workshop-material strong {
  font-size: 0.58rem;
}

.workshop-material-empty {
  color: var(--muted);
  font-size: 0.66rem;
}

.workshop-detail__craft {
  background: rgba(183, 109, 59, 0.9);
  border: 1px solid rgba(247, 240, 223, 0.2);
  border-radius: 8px;
  color: #fff7ec;
  cursor: pointer;
  font-weight: 900;
  min-height: 36px;
}

.workshop-detail__craft:disabled {
  cursor: default;
  opacity: 0.55;
}

.workshop-popup__crafting {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 5px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.workshop-popup .craft-button {
  gap: 8px;
  min-height: 46px;
  padding: 8px 9px;
}

.workshop-popup .craft-button span {
  line-height: 1.32;
  min-width: 0;
}

.workshop-popup .craft-button strong {
  justify-self: end;
  min-width: 34px;
  text-align: center;
}

.log-panel {
  bottom: 62px;
  right: 10px;
  width: min(286px, calc(100vw - 28px));
}

.layout-panel {
  display: none;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  width: min(430px, calc(100vw - 28px));
}

.layout-panel.is-open {
  display: block;
}

.gm-secret {
  background: transparent;
  border: 0;
  height: 28px;
  left: 0;
  min-height: 0;
  opacity: 0;
  padding: 0;
  position: absolute;
  top: 0;
  width: 28px;
  z-index: 20;
}

.gm-panel {
  display: none;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 28px));
  z-index: 9;
}

.gm-panel.is-open {
  display: block;
}

.gm-panel h2 {
  cursor: grab;
  user-select: none;
}

.gm-panel.is-dragging h2 {
  cursor: grabbing;
}

.gm-editor {
  display: grid;
  gap: 7px;
}

.gm-note {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.45;
}

.gm-grid,
.gm-region-grid {
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.gm-region-grid {
  margin-top: 5px;
  max-height: 132px;
  overflow: auto;
  padding-right: 2px;
}

.gm-section {
  background: rgba(247, 240, 223, 0.07);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  padding: 7px;
}

.gm-section strong {
  color: var(--gold);
  font-size: 0.68rem;
}

.gm-editor button {
  font-size: 0.7rem;
  min-height: 29px;
  padding: 4px 7px;
}

.gm-off {
  border-color: rgba(217, 107, 95, 0.55);
}

.command-bar {
  bottom: 10px;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(8, minmax(48px, 1fr));
  left: 50%;
  max-width: min(680px, calc(100vw - 28px));
  position: absolute;
  transform: translateX(-50%);
  width: 100%;
}

.command-bar button {
  font-size: 0.78rem;
  min-height: 32px;
  padding: 5px 7px;
}

.stat-bars,
.region-list,
.crafting,
.castle-status,
.online-players,
.layout-editor {
  display: grid;
  gap: 5px;
}

.layout-help {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.45;
}

.layout-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.layout-tool,
.layout-actions button,
.layout-size button {
  font-size: 0.68rem;
  min-height: 28px;
  padding: 4px 7px;
}

.layout-tool.active {
  background: rgba(215, 168, 75, 0.24);
  border-color: rgba(215, 168, 75, 0.78);
  color: var(--paper);
}

.layout-actions {
  display: grid;
  gap: 5px;
  grid-template-columns: repeat(3, 1fr);
}

.layout-size {
  align-items: center;
  background: rgba(247, 240, 223, 0.07);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  grid-template-columns: 1fr repeat(4, auto);
  padding: 5px;
}

.layout-size strong {
  color: var(--paper);
  font-size: 0.68rem;
  min-width: 0;
}

.stat-row {
  display: grid;
  gap: 3px;
}

.stat-label {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.68rem;
  justify-content: space-between;
}

.bar {
  background: rgba(247, 240, 223, 0.12);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.bar-fill {
  border-radius: inherit;
  height: 100%;
  min-width: 2px;
}

.inventory {
  display: grid;
  gap: 6px;
}

.inventory-section {
  display: grid;
  gap: 5px;
}

.inventory-title {
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
}

.inventory-actions {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inventory-actions button {
  font-size: 0.72rem;
  font-weight: 800;
  min-height: 34px;
  padding: 6px 8px;
}

.storage-list {
  display: grid;
  gap: 4px;
  max-height: 190px;
  overflow: auto;
  padding-right: 2px;
}

.storage-row {
  align-items: center;
  background: rgba(247, 240, 223, 0.07);
  border: 1px solid rgba(243, 234, 216, 0.1);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: minmax(0, 1fr) 44px;
  min-height: 28px;
  padding: 4px;
}

.storage-row span,
.storage-hint {
  color: var(--muted);
  font-size: 0.63rem;
}

.inventory-grid > .storage-hint {
  grid-column: 1 / -1;
}

.storage-row button {
  font-size: 0.62rem;
  min-height: 24px;
  padding: 2px 4px;
}

.inventory-grid,
.weapon-list {
  display: grid;
  gap: 5px;
}

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

.weapon-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.item,
.weapon-chip,
.castle-row,
.online-row {
  align-items: center;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  min-height: 28px;
  padding: 5px;
}

.item {
  align-items: stretch;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 42px;
}

.item.is-empty {
  opacity: 0.48;
}

.inventory-item {
  color: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.inventory-icon {
  align-items: center;
  aspect-ratio: 1;
  display: grid;
  justify-items: center;
  min-height: 46px;
  padding: 4px;
  position: relative;
  text-align: center;
}

.inventory-icon__image {
  display: block;
  height: 34px;
  max-width: 100%;
  object-fit: contain;
  pointer-events: none;
  width: 34px;
}

.inventory-icon__fallback {
  align-items: center;
  background: rgba(215, 168, 75, 0.16);
  border: 1px solid rgba(215, 168, 75, 0.34);
  border-radius: 8px;
  color: var(--paper);
  display: grid;
  font-size: 0.9rem;
  font-weight: 900;
  height: 34px;
  justify-items: center;
  width: 34px;
}

.inventory-count {
  background: rgba(23, 32, 30, 0.86);
  border: 1px solid rgba(247, 240, 223, 0.22);
  border-radius: 999px;
  bottom: 3px;
  color: var(--paper);
  font-size: 0.62rem;
  line-height: 1;
  min-width: 18px;
  padding: 3px 5px;
  position: absolute;
  right: 3px;
}

.inventory-tooltip {
  background: rgba(23, 32, 30, 0.96);
  border: 1px solid rgba(215, 168, 75, 0.48);
  border-radius: 8px;
  bottom: calc(100% + 6px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  color: var(--paper);
  display: none;
  font-size: 0.68rem;
  font-weight: 800;
  left: 50%;
  max-width: 150px;
  opacity: 0;
  padding: 5px 7px;
  pointer-events: none;
  position: absolute;
  transform: translateX(-50%) translateY(4px);
  transition:
    opacity 100ms ease,
    transform 100ms ease;
  white-space: nowrap;
  z-index: 30;
}

.floating-tooltip {
  background: rgba(23, 32, 30, 0.96);
  border: 1px solid rgba(215, 168, 75, 0.48);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  color: var(--paper);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.35;
  max-width: min(220px, calc(100vw - 16px));
  opacity: 0;
  padding: 5px 7px;
  pointer-events: none;
  position: fixed;
  transform: translateY(4px);
  transition:
    opacity 100ms ease,
    transform 100ms ease;
  white-space: normal;
  z-index: 1000;
}

.floating-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.inventory-icon:hover .inventory-tooltip,
.inventory-icon:focus-visible .inventory-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.inventory-item.is-selected {
  background: rgba(215, 168, 75, 0.18);
  border-color: rgba(215, 168, 75, 0.78);
}

.item-main {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  min-width: 0;
}

.item-actions {
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(2, 24px);
}

.item-actions button {
  font-size: 0.62rem;
  min-height: 24px;
  padding: 2px;
}

.item-main span:first-child,
.weapon-chip small,
.castle-row small,
.online-row small,
.region-button small,
.craft-button small {
  color: var(--muted);
  font-size: 0.63rem;
}

.item-main strong,
.weapon-chip span,
.castle-row strong,
.online-row strong {
  color: var(--paper);
}

.weapon-chip {
  color: inherit;
  cursor: pointer;
  display: grid;
  text-align: center;
  width: 100%;
}

.weapon-icon-button {
  align-items: center;
  aspect-ratio: 1;
  justify-items: center;
  min-height: 46px;
  padding: 4px;
  position: relative;
}

.weapon-chip.active {
  background: rgba(215, 168, 75, 0.18);
  border-color: rgba(215, 168, 75, 0.7);
}

.weapon-icon-shape {
  display: block;
  height: 36px;
  position: relative;
  width: 36px;
}

.furniture-icon-shape {
  display: block;
  height: 36px;
  position: relative;
  width: 36px;
}

.weapon-icon-shape::before,
.weapon-icon-shape::after,
.weapon-icon-shape i,
.furniture-icon-shape::before,
.furniture-icon-shape::after,
.furniture-icon-shape i {
  content: "";
  display: block;
  position: absolute;
}

.furniture-icon--chest::before {
  background: #6b4d35;
  border: 2px solid #d7a84b;
  border-radius: 6px;
  bottom: 5px;
  height: 22px;
  left: 3px;
  width: 30px;
}

.furniture-icon--chest::after {
  background: rgba(247, 240, 223, 0.42);
  bottom: 16px;
  height: 2px;
  left: 5px;
  width: 26px;
}

.furniture-icon--chest i {
  background: #d7a84b;
  border-radius: 2px;
  bottom: 8px;
  height: 8px;
  left: 15px;
  width: 6px;
}

.weapon-icon--dagger::before,
.weapon-icon--one-hand-sword::before,
.weapon-icon--great-sword::before {
  background: linear-gradient(90deg, #d9dfd0, #76a7c9 52%, #f7f0df);
  border: 1px solid rgba(23, 32, 30, 0.6);
  border-radius: 999px 999px 4px 4px;
  left: 16px;
  top: 3px;
  transform: rotate(38deg);
  transform-origin: 50% 100%;
  width: 7px;
}

.weapon-icon--dagger::before {
  height: 22px;
}

.weapon-icon--one-hand-sword::before {
  height: 29px;
}

.weapon-icon--great-sword::before {
  height: 34px;
  width: 10px;
}

.weapon-icon--dagger::after,
.weapon-icon--one-hand-sword::after,
.weapon-icon--great-sword::after {
  background: #8b5a32;
  border: 1px solid rgba(23, 32, 30, 0.65);
  border-radius: 999px;
  height: 14px;
  left: 9px;
  top: 23px;
  transform: rotate(38deg);
  width: 6px;
}

.weapon-icon--great-sword::after {
  left: 8px;
  top: 25px;
}

.weapon-icon--wood-club::before {
  background: #8b5a32;
  border: 1px solid rgba(23, 32, 30, 0.65);
  border-radius: 999px 999px 6px 6px;
  height: 32px;
  left: 15px;
  top: 2px;
  transform: rotate(36deg);
  width: 9px;
}

.weapon-icon--wood-club::after {
  background: #44372f;
  border-radius: 999px;
  height: 13px;
  left: 8px;
  top: 25px;
  transform: rotate(36deg);
  width: 6px;
}

.weapon-icon--wood-spear::before,
.weapon-icon--stone-spear::before {
  background: #8b5a32;
  border-radius: 999px;
  height: 34px;
  left: 16px;
  top: 4px;
  transform: rotate(34deg);
  width: 5px;
}

.weapon-icon--wood-spear::after,
.weapon-icon--stone-spear::after {
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 16px solid #d9dfd0;
  height: 0;
  left: 15px;
  top: 1px;
  transform: rotate(34deg);
  width: 0;
}

.weapon-icon--stone-axe::before {
  background: #8b5a32;
  border-radius: 999px;
  height: 34px;
  left: 17px;
  top: 5px;
  transform: rotate(34deg);
  width: 5px;
}

.weapon-icon--stone-axe::after {
  background: #9ba09d;
  border: 1px solid rgba(23, 32, 30, 0.65);
  border-radius: 70% 35% 70% 35%;
  height: 17px;
  left: 16px;
  top: 3px;
  transform: rotate(34deg);
  width: 19px;
}

.weapon-icon--rift-blade::before {
  background: linear-gradient(90deg, #4a244f, #d66fa2 54%, #f7f0df);
  border: 1px solid rgba(247, 240, 223, 0.5);
  clip-path: polygon(50% 0, 66% 24%, 62% 100%, 38% 100%, 34% 24%);
  height: 34px;
  left: 15px;
  top: 1px;
  transform: rotate(38deg);
  width: 10px;
}

.weapon-icon--rift-blade::after {
  background: #44372f;
  border-radius: 999px;
  height: 14px;
  left: 8px;
  top: 25px;
  transform: rotate(38deg);
  width: 7px;
}

.weapon-icon--scythe::before {
  border: 5px solid transparent;
  border-left-color: #d9dfd0;
  border-radius: 50%;
  height: 24px;
  left: 8px;
  top: 1px;
  transform: rotate(-28deg);
  width: 24px;
}

.weapon-icon--scythe::after {
  background: #8b5a32;
  border-radius: 999px;
  height: 34px;
  left: 12px;
  top: 5px;
  transform: rotate(34deg);
  width: 5px;
}

.weapon-icon--staff::before {
  background: #8b5a32;
  border-radius: 999px;
  height: 34px;
  left: 15px;
  top: 2px;
  transform: rotate(22deg);
  width: 5px;
}

.weapon-icon--staff::after {
  background: radial-gradient(circle, #f7f0df 0 24%, #d66fa2 28% 56%, #a991c7 62% 100%);
  border: 1px solid rgba(247, 240, 223, 0.52);
  border-radius: 50%;
  height: 15px;
  left: 17px;
  top: 0;
  width: 15px;
}

.weapon-icon--dumbbell::before,
.weapon-icon--dumbbell::after {
  background: #6f7f7e;
  border: 2px solid rgba(23, 32, 30, 0.65);
  border-radius: 50%;
  height: 13px;
  top: 12px;
  width: 13px;
}

.weapon-icon--dumbbell::before {
  left: 4px;
}

.weapon-icon--dumbbell::after {
  right: 4px;
}

.weapon-icon--dumbbell i {
  background: #b9c3b5;
  border-radius: 999px;
  height: 5px;
  left: 13px;
  top: 18px;
  width: 12px;
}

.castle-row,
.online-row {
  display: grid;
  grid-template-columns: 1fr auto;
}

.online-dot {
  border-radius: 999px;
  display: inline-block;
  height: 8px;
  margin-right: 6px;
  width: 8px;
}

.region-button,
.craft-button {
  align-items: center;
  display: grid;
  gap: 3px;
  grid-template-columns: 1fr auto;
  min-height: 32px;
  padding: 6px 7px;
  text-align: left;
}

.region-button.active {
  border-color: rgba(215, 168, 75, 0.8);
  box-shadow: inset 0 0 0 1px rgba(215, 168, 75, 0.36);
}

.log {
  color: #d9dfd0;
  display: flex;
  flex-direction: column;
  font-size: 0.68rem;
  gap: 5px;
  line-height: 1.45;
  max-height: 136px;
  overflow: auto;
  padding-right: 4px;
}

.log p {
  border-bottom: 1px solid rgba(247, 240, 223, 0.09);
  padding-bottom: 6px;
}

.demon-panel {
  background: rgba(25, 36, 33, 0.88);
  border: 1px solid rgba(215, 168, 75, 0.42);
  border-radius: 8px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.36);
  display: none;
  left: 50%;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  z-index: 8;
  backdrop-filter: blur(14px);
}

.recipe-panel {
  max-width: min(420px, calc(100vw - 28px));
}

.recipe-panel .demon-content {
  max-height: min(62dvh, 520px);
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.recipe-card {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 92px minmax(0, 1fr);
}

.recipe-card__image {
  align-self: stretch;
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  height: 92px;
  object-fit: contain;
  width: 92px;
}

.recipe-card__image--empty {
  position: relative;
}

.recipe-card__image--empty::after {
  color: rgba(243, 234, 216, 0.45);
  content: "?";
  font-size: 1.4rem;
  font-weight: 800;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
}

.recipe-card__body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.recipe-card__body small,
.recipe-card__body span {
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.35;
}

.sleep-panel {
  max-width: min(390px, calc(100vw - 28px));
}

.map-panel {
  max-width: min(570px, calc(100vw - 28px));
}

.world-map {
  background: rgba(9, 14, 13, 0.72);
  border: 1px solid rgba(243, 234, 216, 0.18);
  border-radius: 8px;
  display: block;
  height: auto;
  max-height: 54vh;
  width: 100%;
}

.map-summary {
  color: #d9dfd0;
  display: grid;
  font-size: 0.72rem;
  gap: 4px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  line-height: 1.35;
  margin-top: 8px;
}

.map-summary span {
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.1);
  border-radius: 8px;
  padding: 5px 6px;
}

.map-legend {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.66rem;
  gap: 8px;
  margin-top: 8px;
}

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 8px;
  margin-right: 4px;
  width: 8px;
}

.legend-player { background: #f7f0df; }
.legend-castle { background: #d7a84b; }
.legend-resource { background: #4aa79c; }
.legend-settlement { background: #76a7c9; }
.legend-danger { background: #d96b5f; }

.demon-panel.is-open {
  display: block;
}

.demon-panel__header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.demon-panel__eyebrow {
  color: var(--gold);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.demon-close {
  border-radius: 999px;
  font-size: 1rem;
  line-height: 1;
  min-height: 28px;
  min-width: 28px;
  padding: 0;
}

.demon-tabs {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 10px;
}

.demon-tab {
  font-size: 0.72rem;
  min-height: 30px;
  padding: 5px 6px;
}

.demon-tab.active {
  background: rgba(215, 168, 75, 0.2);
  border-color: rgba(215, 168, 75, 0.8);
}

.demon-content {
  color: #d9dfd0;
  display: grid;
  font-size: 0.78rem;
  gap: 8px;
  line-height: 1.5;
}

.demon-line,
.demon-task {
  background: rgba(247, 240, 223, 0.08);
  border: 1px solid rgba(243, 234, 216, 0.12);
  border-radius: 8px;
  padding: 8px;
}

.demon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}

.sleep-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.demon-actions button {
  font-size: 0.76rem;
  min-height: 32px;
  padding: 6px 8px;
}

@media (max-width: 1180px) {
  .craft-panel {
    left: auto;
    right: 240px;
  }

  .castle-panel {
    top: 252px;
  }
}

@media (max-width: 860px) {
  .app {
    min-height: 620px;
  }

  .topbar {
    left: 12px;
    right: 12px;
    top: 10px;
  }

  .status-panel {
    left: 10px;
    top: 74px;
    width: min(214px, calc(50vw - 16px));
  }

  .route-panel {
    right: 10px;
    top: 74px;
    width: min(214px, calc(50vw - 16px));
  }

  .craft-panel {
    right: 10px;
    top: 154px;
    width: min(214px, calc(50vw - 16px));
  }

  .craft-panel.dock-right.is-collapsed {
    transform: translateX(calc(100% + 10px));
  }

  .inventory-panel {
    bottom: 70px;
    left: 10px;
    width: min(230px, calc(50vw - 16px));
  }

  .log-panel {
    bottom: 70px;
    right: 10px;
    width: min(286px, calc(50vw - 16px));
  }

  .castle-panel {
    top: 236px;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 1.35rem;
  }

  .clock {
    padding: 6px 8px;
  }

  .status-panel,
  .route-panel,
  .inventory-panel,
  .log-panel {
    width: calc(100vw - 24px);
  }

  .inventory-panel {
    bottom: 210px;
  }

  .log-panel {
    bottom: 96px;
  }

  .log {
    max-height: 74px;
  }

  .command-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: calc(100vw - 24px);
  }

  .demon-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .character-choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .character-card {
    min-height: 220px;
  }

  .map-summary {
    grid-template-columns: 1fr;
  }
}
