/* ===================== Worldo — pixel RPG ===================== */
:root {
  --ink: #14101f;
  --ink-2: #1d1730;
  --panel: rgba(24, 18, 40, 0.92);
  --panel-line: #3a2f58;
  --parchment: #efe4c8;
  --gold: #e8c24b;
  --gold-dk: #b8912f;
  --red: #d3493f;
  --green: #5ab54a;
  --blue: #4a9de0;
  --text: #efe9ff;
  --text-dim: #b3a9cf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0c0916;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none; touch-action: none;
}
[hidden] { display: none !important; }

#game {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  background: #2a3d5c;
}

/* ---------- passcode gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(1000px 700px at 50% -10%, #2a2050, transparent 65%),
    linear-gradient(180deg, #171029, #0c0916);
  transition: opacity .42s ease;
}
.gate.gate-out { opacity: 0; pointer-events: none; }
.gate-panel {
  width: 100%; max-width: 360px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 18px; padding: 30px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
}
.gate-word {
  margin: 0; font-size: 2.4rem; font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(180deg, #ffe9a8, var(--gold) 55%, var(--gold-dk));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.gate-sub { margin: 0; color: var(--text-dim); font-size: .95rem; }
#gate-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.gate-input {
  width: 100%; padding: 12px 14px; font-size: 1rem; text-align: center; letter-spacing: .18em;
  background: var(--ink); color: var(--text);
  border: 1.5px solid var(--panel-line); border-radius: 10px; outline: none;
}
.gate-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,194,75,.2); }
.gate-go { font-size: 1rem; padding: 12px; }
.gate-err { margin: 0; color: var(--red); font-size: .85rem; font-weight: 700; }
.gate-panel.gate-shake { animation: gateShake .4s ease; }
@keyframes gateShake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(5px); }
  50% { transform: translateX(-7px); }
}

/* ---------- overlays base ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1000px 700px at 50% -10%, #2a2050, transparent 65%),
    linear-gradient(180deg, #171029, #0c0916);
  overflow-y: auto;
}
.title-inner {
  width: 100%; max-width: 640px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark { width: 48px; height: 48px; image-rendering: pixelated; filter: drop-shadow(0 3px 5px rgba(0,0,0,.55)); }
.logo-word {
  margin: 0; font-size: 3.2rem; font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(180deg, #ffe9a8, var(--gold) 55%, var(--gold-dk));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.tagline { margin: -6px 0 4px; color: var(--text-dim); font-size: .98rem; letter-spacing: .01em; }

/* continue */
.continue-card {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 18px; border-radius: 12px; cursor: pointer;
  background: linear-gradient(180deg, #2c8a4a, #1f6a37);
  border: 1px solid #43b567; color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  transition: transform .1s, filter .15s;
}
.continue-card:hover { filter: brightness(1.08); }
.continue-card:active { transform: scale(.98); }
.cont-title { font-weight: 800; font-size: 1.05rem; }
.cont-sub { font-size: .82rem; opacity: .9; }

/* creator */
.creator {
  width: 100%;
  display: flex; gap: 18px;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 16px; padding: 18px;
  box-shadow: 0 16px 44px rgba(0,0,0,.45);
}
.creator-left { flex: 0 0 auto; }
#cc-preview {
  width: 176px; height: 176px;
  image-rendering: pixelated;
  background: radial-gradient(circle at 50% 40%, #2b2450, #1a1430);
  border: 1px solid var(--panel-line); border-radius: 12px;
}
.creator-right { flex: 1; text-align: left; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); font-weight: 700; }
.name-input {
  width: 100%; padding: 10px 12px; font-size: 1rem;
  background: var(--ink); color: var(--text);
  border: 1.5px solid var(--panel-line); border-radius: 9px; outline: none;
}
.name-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,194,75,.2); }

.cls-grid { display: flex; flex-direction: column; gap: 6px; }
.cls-btn {
  display: flex; flex-direction: column; gap: 1px; text-align: left;
  padding: 8px 12px; border-radius: 9px; cursor: pointer;
  background: var(--ink); border: 1.5px solid var(--panel-line); color: var(--text);
  transition: border-color .12s, background .12s;
}
.cls-btn:hover { border-color: #5a4a80; }
.cls-btn.active { border-color: var(--gold); background: #241a3a; }
.cls-name { font-weight: 800; font-size: .95rem; }
.cls-desc { font-size: .76rem; color: var(--text-dim); }

.appearance { display: flex; gap: 18px; }
.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid rgba(255,255,255,.15);
}
.swatch.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232,194,75,.35); }

.start-btn {
  width: 100%; max-width: 420px;
  padding: 15px; border: 0; border-radius: 12px; cursor: pointer;
  font-size: 1.15rem; font-weight: 900; letter-spacing: .01em;
  color: #2a1c06;
  background: linear-gradient(180deg, #ffe08a, var(--gold) 60%, var(--gold-dk));
  box-shadow: 0 8px 22px rgba(232,194,75,.28), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .1s, filter .15s;
}
.start-btn:hover { filter: brightness(1.05); }
.start-btn:active { transform: scale(.98); }
.footnote { color: var(--text-dim); font-size: .76rem; margin: 2px 0 8px; }

/* ---------- dialogue ---------- */
.dialogue {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 15; width: min(560px, calc(100vw - 32px));
  cursor: pointer;
}
.dlg-inner {
  background: var(--panel); border: 2px solid var(--gold-dk);
  border-radius: 14px; padding: 14px 18px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.dlg-name { color: var(--gold); font-weight: 800; font-size: .95rem; margin-bottom: 4px; }
.dlg-text { font-size: 1.02rem; line-height: 1.4; min-height: 2.6em; }
.dlg-hint { text-align: right; color: var(--text-dim); font-size: .74rem; margin-top: 4px; }

/* ---------- death ---------- */
.death {
  position: fixed; inset: 0; z-index: 18;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 50%, rgba(90,10,10,.4), rgba(6,4,10,.82));
  animation: fade .3s ease;
}
.death-inner { text-align: center; }
.death-title { font-size: 2.4rem; font-weight: 900; color: #e5554a; text-shadow: 0 3px 0 rgba(0,0,0,.4); letter-spacing: .04em; }
.death-sub { color: var(--text-dim); margin-top: 6px; }

/* ---------- intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 19;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1000px 700px at 50% 0%, #241b47, transparent 60%), rgba(8, 6, 14, .86);
  animation: fade .3s ease;
}
.intro-panel {
  width: 100%; max-width: 500px; text-align: center;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 18px; padding: 26px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
}
.intro-mark { width: 44px; height: 44px; image-rendering: pixelated; filter: drop-shadow(0 3px 5px rgba(0,0,0,.5)); }
.intro-title {
  margin: 6px 0 14px; font-size: 1.7rem; font-weight: 900; letter-spacing: -.01em;
  background: linear-gradient(180deg, #ffe9a8, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.intro-panel p { color: var(--text-dim); line-height: 1.55; margin: 8px 0; font-size: .98rem; }
.intro-panel .start-btn { margin-top: 18px; }

/* ---------- loading (shows the real generated world) ---------- */
.loading {
  position: fixed; inset: 0; z-index: 22;
  background: #0c0916;
  transition: opacity .42s ease;
}
.load-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block; image-rendering: pixelated;
}
.load-panel {
  position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 40px));
  display: flex; flex-direction: column; align-items: center; gap: 15px;
  text-align: center;
}
.load-logo { display: flex; align-items: center; gap: 12px; }
.load-logo .logo-mark { width: 40px; height: 40px; }
.load-word {
  font-size: 2.4rem; font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(180deg, #ffe9a8, var(--gold) 55%, var(--gold-dk));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.load-bar {
  width: 100%; height: 10px; border-radius: 999px;
  background: rgba(255,255,255,.1);
  border: 1px solid var(--panel-line); overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
.load-bar-fill {
  width: 0%; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-dk), var(--gold) 60%, #ffe9a8);
  transition: width .12s linear;
}
.load-tip {
  color: var(--text-dim); font-size: .92rem; line-height: 1.45;
  max-width: 460px; min-height: 2.6em;
  text-shadow: 0 2px 6px rgba(0,0,0,.6);
}

/* ---------- shop ---------- */
.shop {
  position: fixed; inset: 0; z-index: 19;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(8, 6, 14, .72); backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
.shop-panel {
  position: relative; width: 100%; max-width: 440px;
  background: var(--panel); border: 2px solid var(--gold-dk);
  border-radius: 16px; padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  animation: rise .22s ease;
}
.shop-x {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--ink); color: var(--text-dim); font-size: .85rem;
}
.shop-x:hover { color: var(--text); }
.shop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding-right: 28px; }
.shop-head h2 { margin: 0; font-size: 1.3rem; color: var(--gold); }
.shop-coins-wrap { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
#shop-coin-ico canvas { width: 18px; height: 18px; image-rendering: pixelated; display: block; }
.shop-items { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--ink); border: 1px solid var(--panel-line);
  border-radius: 11px; padding: 10px 12px;
}
.si-icon { width: 30px; height: 30px; flex: 0 0 auto; }
.si-icon canvas { width: 30px; height: 30px; image-rendering: pixelated; display: block; }
.si-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.si-name { font-weight: 700; font-size: .96rem; }
.si-lvl { font-size: .72rem; color: var(--gold); font-weight: 700; margin-left: 4px; }
.si-desc { font-size: .8rem; color: var(--text-dim); }
.si-buy {
  flex: 0 0 auto; border: 0; border-radius: 9px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 12px; font-weight: 800; font-size: .9rem; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffe08a, var(--gold) 60%, var(--gold-dk)); color: #2a1c06;
  transition: filter .12s, transform .08s;
}
.si-coin { width: 15px; height: 15px; image-rendering: pixelated; display: block; }
.si-buy:hover { filter: brightness(1.06); }
.si-buy:active { transform: scale(.96); }
.si-buy.disabled { background: #2c2440; color: #6b6288; cursor: default; }
.shop-foot { text-align: center; color: var(--text-dim); font-size: .78rem; margin: 14px 0 0; }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- chat (multiplayer) ---------- */
.chat {
  position: fixed; left: 14px; bottom: 66px; z-index: 14;
  width: min(360px, 70vw);
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.chat-log {
  display: flex; flex-direction: column; gap: 3px;
  max-height: 168px; overflow-y: auto;
}
.chat-msg {
  align-self: flex-start;
  background: rgba(18, 14, 30, 0.72);
  border: 1px solid var(--panel-line);
  padding: 4px 9px; border-radius: 10px;
  font-size: .84rem; line-height: 1.25; color: var(--text);
  max-width: 100%; word-break: break-word;
}
.chat-msg .chat-from { color: #9ad0ff; font-weight: 700; }
.chat-msg.self { background: rgba(46, 40, 70, 0.82); }
.chat-msg.self .chat-from { color: var(--gold); }
.chat-input {
  pointer-events: auto;
  width: 100%; padding: 9px 12px; border-radius: 10px;
  background: var(--ink); color: var(--text);
  border: 1.5px solid var(--gold-dk); outline: none; font-size: .92rem;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%);
  z-index: 30;
  background: var(--panel); border: 1px solid var(--panel-line);
  color: var(--text); padding: 9px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toastIn .2s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; } }

@media (max-width: 560px) {
  .creator { flex-direction: column; align-items: center; }
  .creator-right { width: 100%; }
  .logo-word { font-size: 2.6rem; }
}
