:root {
  color-scheme: dark;
  --ink: #f6f1e7;
  --muted: #b8b7af;
  --line: rgba(255, 255, 255, 0.2);
  --panel: rgba(9, 12, 11, 0.84);
  --accent: #efb84f;
  --green: #66c47d;
}

* { box-sizing: border-box; }

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050706;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

body.is-playing,
body.is-playing * { cursor: none !important; }

#world {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.game-bar {
  position: fixed;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.brand,
.game-bar button,
.game-bar > span {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand { padding: 13px 15px; }
.game-bar > span { font-size: 14px; color: var(--muted); }
.bar-actions { display: flex; justify-content: flex-end; height: 100%; }

.game-bar button,
.icon-button {
  min-width: 48px;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.status-panel {
  position: fixed;
  z-index: 9;
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  gap: 14px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  font-weight: 750;
  backdrop-filter: blur(12px);
}

.status-panel b { color: #ff6d65; }
.status-panel span:nth-child(2) b { color: var(--accent); }

#crosshair {
  position: fixed;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#mouse-capture {
  position: fixed;
  z-index: 7;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 44px);
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 4px;
  padding: 10px 13px;
  color: white;
  background: rgba(7, 9, 8, 0.82);
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

#mouse-capture[hidden] { display: none; }

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: white;
  box-shadow: 0 1px 3px #000;
}

#crosshair::before { top: 9px; left: 0; width: 20px; height: 2px; }
#crosshair::after { top: 0; left: 9px; width: 2px; height: 20px; }

#target-label,
#toast {
  position: fixed;
  z-index: 8;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 10px;
  background: rgba(0, 0, 0, 0.68);
  font-size: 12px;
  font-weight: 750;
  pointer-events: none;
}

#target-label { top: calc(50% + 24px); }
#toast { top: 104px; opacity: 0; transition: opacity 160ms ease; }
#toast.show { opacity: 1; }

#hotbar {
  position: fixed;
  z-index: 10;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  display: flex;
  gap: 4px;
  max-width: calc(100% - 24px);
  padding: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  transform: translateX(-50%);
}

#hotbar::-webkit-scrollbar { display: none; }

.hotbar-slot {
  position: relative;
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(7, 9, 8, 0.82);
  color: white;
  cursor: pointer;
}

.hotbar-slot.selected { border-color: var(--accent); transform: translateY(-4px); }
.slot-number { position: absolute; top: 2px; left: 4px; color: var(--muted); font-size: 9px; font-weight: 900; }
.block-icon { display: block; width: 30px; height: 30px; margin: auto; }
.block-icon svg { display: block; width: 100%; height: 100%; }
.slot-count { position: absolute; right: 4px; bottom: 2px; font-size: 11px; font-weight: 800; }

.touch-controls { display: none; }

dialog {
  width: min(680px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c100f;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(8px); }
.dialog-card { display: grid; gap: 18px; padding: 24px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 12px; font-weight: 850; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(36px, 8vw, 64px); line-height: .94; }
h2 { margin-bottom: 0; font-size: 18px; }
.intro { color: var(--muted); line-height: 1.55; }
.dialog-card > label { display: grid; gap: 8px; font-size: 13px; font-weight: 800; }
input[type="text"], input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 13px;
  color: var(--ink);
  background: #050706;
}

.option-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.option-row > div { display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.option-row .world-type-option { grid-column: 1 / -1; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 10px; text-align: center; }
.segmented input:checked + span { color: #111; background: var(--accent); }

.primary,
.save-row button {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 14px;
  color: #15120c;
  background: var(--accent);
  font-weight: 850;
  cursor: pointer;
}

.primary:disabled { opacity: 0.48; cursor: wait; }

.save-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 18px; }
.save-head span { color: var(--muted); font-size: 12px; }
#world-list { display: grid; gap: 8px; }
.save-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); }
.save-row small { display: block; margin-top: 3px; color: var(--muted); }
.save-row .delete { color: #ffaaa0; background: transparent; }
.empty-save { color: var(--muted); }
details { border-top: 1px solid var(--line); padding-top: 16px; color: var(--muted); }
summary { color: var(--ink); font-weight: 800; cursor: pointer; }
details li { margin: 8px 0; line-height: 1.45; }

@media (pointer: coarse), (max-width: 820px) {
  .game-bar { grid-template-columns: 1fr auto; }
  .game-bar > span { display: none; }
  .touch-controls { display: block; }
  #mouse-capture { display: none; }
  #hotbar {
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 122px);
    display: grid;
    grid-template-columns: repeat(6, 44px);
    max-width: none;
    overflow: visible;
  }
  .hotbar-slot { width: 44px; height: 44px; flex-basis: 44px; }
  .move-pad { position: fixed; z-index: 10; left: max(14px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); gap: 4px; }
  .move-pad button, .action-pad button { border: 1px solid var(--line); border-radius: 4px; color: white; background: rgba(7, 9, 8, .8); font-size: 20px; font-weight: 900; }
  .move-pad button[data-move="forward"] { grid-column: 2; }
  .move-pad button[data-move="left"] { grid-column: 1; grid-row: 2; }
  .move-pad button[data-move="back"] { grid-column: 2; grid-row: 2; }
  .move-pad button[data-move="right"] { grid-column: 3; grid-row: 2; }
  .action-pad { position: fixed; z-index: 10; right: max(14px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3, 48px); gap: 5px; }
  .action-pad button { height: 48px; }
}

@media (max-width: 560px) {
  .status-panel { max-width: calc(100% - 24px); gap: 9px; font-size: 11px; }
  .brand { font-size: 14px; }
  .game-bar button { font-size: 12px; }
  #hotbar { width: auto; grid-template-columns: repeat(6, 40px); }
  .hotbar-slot { width: 40px; height: 42px; flex-basis: 40px; }
  .block-icon { width: 25px; height: 25px; }
  .option-row { grid-template-columns: 1fr; }
  .dialog-card { padding: 18px; }
  .save-row { grid-template-columns: 1fr auto; }
  .save-row .delete { grid-column: 2; }
}
