:root {
  --sky: #29b6f6; --ink: #3a2a20; --card: #fffdf7; --accent: #ff7043; --ok: #43a047; --err: #e53935;
  --gold: #ffca28; --muted: #8d7b6e; --line: #eadfce;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink);
  font-family: "Nunito", "Trebuchet MS", "Segoe UI", Arial, sans-serif; touch-action: none; user-select: none; }
input, button { font: inherit; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- auth */
#auth { display: flex; padding: 16px; overflow: auto; touch-action: auto;
  background: radial-gradient(circle at 80% 15%, #fff59d 0 60px, transparent 61px), linear-gradient(#4fc3f7, #b3e5fc 60%, #ffe082 60%, #ffe082 70%, #7ccf5a 70%); }
.card { background: var(--card); border-radius: 24px; box-shadow: 0 10px 0 rgba(0,0,0,.12), 0 20px 40px rgba(0,0,0,.15); border: 3px solid var(--ink); }
.auth-card { width: min(420px, 100%); padding: 22px 22px 16px; text-align: center; margin: auto; flex-shrink: 0; }
@media (max-height: 520px) {
  .auth-card { width: min(640px, 100%); padding: 12px 18px 10px; }
  .auth-card .logo { width: 48px; height: 48px; margin-top: 0; float: left; }
  .auth-card h1 { font-size: 22px; } .auth-card .by { margin-bottom: 8px; }
  .auth-card .tabs { margin-bottom: 8px; clear: both; }
  #f-register { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
  #f-register.hidden { display: none; }
  #f-register .sex, #f-register .btn { grid-column: 1 / -1; }
  .form input:not([type=radio]) { padding: 8px 11px; }
  .btn.big { padding: 9px; margin-top: 2px; }
}
.logo { width: 76px; height: 76px; margin-top: -60px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.15)); }
h1 { margin: 4px 0 0; font-size: 28px; color: #0277bd; letter-spacing: .5px; }
.by { margin: 0 0 14px; color: var(--muted); font-weight: 700; }
.tabs { display: flex; gap: 6px; background: #f3ead9; padding: 5px; border-radius: 14px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 10px; font-weight: 800; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(0,0,0,.1); }
.form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.form label { font-weight: 800; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.form input:not([type=radio]) { padding: 11px 13px; border: 2px solid var(--line); border-radius: 12px; font-size: 16px; background: #fff; outline: none; }
.form input:focus { border-color: var(--sky); }
.sex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 800; font-size: 14px; }
.sex > span { width: 100%; }
.pill { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 6px; padding: 8px 12px; border: 2px solid var(--line);
  border-radius: 999px; cursor: pointer; background: #fff; font-weight: 800; }
.pill:has(input:checked) { border-color: var(--sky); background: #e1f5fe; }
.err { color: var(--err); font-weight: 800; min-height: 1.2em; margin: 10px 0 0; }

.btn { border: 3px solid var(--ink); background: var(--gold); color: var(--ink); font-weight: 900; padding: 8px 16px; border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink); cursor: pointer; transition: transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.big { font-size: 19px; padding: 12px; margin-top: 6px; }
.btn.blue { background: #4fc3f7; } .btn.green { background: #81c784; } .btn.red { background: #ef9a9a; } .btn.gray { background: #e0e0e0; }
.btn.small { padding: 4px 10px; font-size: 13px; border-width: 2px; box-shadow: 0 3px 0 var(--ink); border-radius: 10px; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ---------- joc */
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; flex-wrap: wrap; }
.hud-box { background: rgba(255,253,247,.94); border: 3px solid var(--ink); border-radius: 14px; padding: 5px 12px; font-weight: 900; display: flex; gap: 12px; align-items: center; box-shadow: 0 3px 0 rgba(0,0,0,.2); }
.hud-box.online { margin-left: auto; margin-right: auto; }
.hud-box.loc { background: #e1f5fe; }
#hud-name { color: #0277bd; }
#theme-banner { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); background: #4a148c; color: #fff; padding: 6px 16px; border-radius: 999px; font-weight: 800;
  border: 3px solid var(--ink); max-width: calc(100% - 140px); text-align: center; font-size: 14px; pointer-events: none; }
#hud-right { position: absolute; right: 8px; top: 64px; display: flex; flex-direction: column; gap: 8px; }
.rb { width: 58px; height: 58px; border-radius: 16px; border: 3px solid var(--ink); background: #fffdf7; font-size: 24px; cursor: pointer; box-shadow: 0 4px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; padding: 0; }
.rb span { font-size: 9px; font-weight: 900; margin-top: 3px; }
.rb:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.round { position: absolute; left: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--gold); font-size: 32px; box-shadow: 0 4px 0 var(--ink); cursor: pointer; }
#emote-grid { position: absolute; left: 14px; bottom: 90px; display: grid; grid-template-columns: repeat(4, 50px); gap: 6px; background: var(--card); border: 3px solid var(--ink); border-radius: 18px; padding: 8px; }
#emote-grid button { font-size: 28px; border: 0; background: #f3ead9; border-radius: 12px; height: 50px; cursor: pointer; }
#emote-grid button:active { background: #ffe082; }
#btn-interact { position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); font-size: 20px; font-weight: 900; padding: 12px 26px; border-radius: 999px;
  border: 3px solid var(--ink); background: #81c784; box-shadow: 0 5px 0 var(--ink); cursor: pointer; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.06); } }
#house-bar { position: absolute; left: 90px; bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#house-bar .pill { border: 3px solid var(--ink); }
#edit-bar { position: absolute; left: 8px; right: 76px; bottom: 90px; background: rgba(255,253,247,.96); border: 3px solid var(--ink); border-radius: 18px; padding: 8px;
  display: flex; gap: 8px; overflow-x: auto; align-items: stretch; touch-action: pan-x; }
#edit-bar .slot { flex: 0 0 auto; width: 84px; border: 2px solid var(--line); border-radius: 12px; background: #fff; text-align: center; font-size: 11px; font-weight: 800; padding: 4px; cursor: pointer; }
#edit-bar .slot.sel { border-color: var(--accent); background: #fff3e0; }
#edit-bar .slot canvas { width: 64px; height: 64px; }
#edit-bar .tools { display: flex; flex-direction: column; gap: 6px; justify-content: center; flex: 0 0 auto; }
#edit-bar .hint { align-self: center; font-weight: 800; color: var(--muted); padding: 0 10px; white-space: nowrap; }

/* ---------- modal */
#modal { position: fixed; inset: 0; background: rgba(30,20,10,.45); display: flex; align-items: center; justify-content: center; padding: 10px; z-index: 10; }
.modal-card { position: relative; background: var(--card); border: 3px solid var(--ink); border-radius: 24px; width: min(880px, 100%); max-height: calc(100% - 10px);
  overflow: auto; padding: 18px; box-shadow: 0 10px 0 rgba(0,0,0,.2); touch-action: pan-y; user-select: text; }
.x { position: sticky; float: right; top: 0; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); background: #ef9a9a; font-weight: 900; cursor: pointer; z-index: 2; }
.modal-card h2 { margin: 0 0 4px; color: #0277bd; }
.modal-card .sub { color: var(--muted); font-weight: 700; margin: 0 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.item { border: 2px solid var(--line); border-radius: 16px; background: #fff; padding: 8px; text-align: center; display: flex; flex-direction: column; gap: 4px; align-items: center; position: relative; }
.item canvas { width: 96px; height: 96px; background: #f7f1e6; border-radius: 12px; }
.item .nm { font-weight: 800; font-size: 13px; line-height: 1.15; min-height: 2.3em; }
.item .pr { font-weight: 900; }
.item .badge { position: absolute; top: 6px; left: 6px; background: #6a1b9a; color: #fff; font-size: 10px; font-weight: 900; padding: 2px 6px; border-radius: 6px; }
.item .own { position: absolute; top: 6px; right: 6px; background: var(--ok); color: #fff; font-size: 10px; font-weight: 900; padding: 2px 6px; border-radius: 6px; }
.item.sel { border-color: var(--accent); background: #fff3e0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 12px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 800; cursor: pointer; }
.chip.active { border-color: var(--ink); background: var(--gold); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.sw { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.sw.active { box-shadow: 0 0 0 3px var(--ink); }
.wardrobe { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
.wardrobe .preview { background: linear-gradient(#e1f5fe, #fff8e1); border-radius: 18px; border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 10px; gap: 10px; position: sticky; top: 0; align-self: start; }
.wardrobe .preview canvas { width: 220px; height: 260px; }
.wardrobe h4 { margin: 8px 0 2px; }
.wardrobe .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.wardrobe .item canvas { width: 70px; height: 70px; }
.wardrobe .item { padding: 5px; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.riddle-q { font-size: 22px; font-weight: 900; background: #fff8e1; border: 2px dashed #ffb300; border-radius: 16px; padding: 18px; margin: 10px 0; }
.text-in { padding: 11px 13px; border: 2px solid var(--line); border-radius: 12px; font-size: 17px; flex: 1; min-width: 180px; }
.plist { display: flex; flex-direction: column; gap: 6px; }
.plist .pr-row { display: flex; align-items: center; gap: 10px; border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; background: #fff; }
.plist canvas { width: 44px; height: 52px; }
.plist .nm { font-weight: 900; flex: 1; }
.trade { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.trade .side { border: 2px solid var(--line); border-radius: 16px; padding: 10px; background: #fff; }
.trade .side.ready { border-color: var(--ok); background: #f1f8e9; }
.trade .grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.trade .item canvas { width: 56px; height: 56px; }
.trade .item { cursor: pointer; padding: 4px; }
.mini-num { width: 80px; padding: 6px; border: 2px solid var(--line); border-radius: 10px; }
#mg { width: 100%; max-width: 640px; aspect-ratio: 4/3; display: block; margin: 0 auto; background: linear-gradient(#1a237e, #4a148c); border-radius: 16px; touch-action: none; }
.bigmsg { text-align: center; font-size: 20px; font-weight: 900; margin: 10px 0; }

#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 20; pointer-events: none; align-items: center; }
.toast { background: var(--card); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 16px; font-weight: 800; box-shadow: 0 4px 0 rgba(0,0,0,.2); animation: tin .25s; max-width: 90vw; text-align: center; }
.toast.ok { background: #e8f5e9; } .toast.err { background: #ffebee; } .toast.big { background: #fff59d; font-size: 18px; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }
#loading { position: fixed; inset: 0; background: rgba(41,182,246,.92); color: #fff; font-size: 26px; font-weight: 900; display: flex; align-items: center; justify-content: center; z-index: 30; }

@media (max-width: 700px), (max-height: 500px) {
  .hud-box { padding: 3px 8px; gap: 8px; font-size: 13px; border-width: 2px; }
  #hud-online-l { display: none; }
  .rb { width: 46px; height: 46px; font-size: 19px; border-radius: 13px; }
  .rb span { display: none; }
  #hud-right { top: 48px; gap: 6px; }
  #theme-banner { top: 44px; font-size: 12px; padding: 4px 10px; }
  .wardrobe { grid-template-columns: 170px 1fr; gap: 10px; }
  .wardrobe .preview { padding: 6px; gap: 6px; }
  .wardrobe .preview canvas { width: 150px; height: 178px; }
  .wardrobe .preview .btn.big { font-size: 16px; padding: 7px 10px; }
  .trade { grid-template-columns: 1fr; }
  .round { width: 54px; height: 54px; font-size: 26px; }
  #emote-grid { bottom: 76px; grid-template-columns: repeat(4, 44px); } #emote-grid button { height: 44px; font-size: 24px; }
  #house-bar { left: 78px; } #edit-bar { bottom: 70px; right: 60px; padding: 4px 6px; gap: 6px; border-radius: 14px; }
  #edit-bar .slot { width: 62px; font-size: 9px; padding: 2px; } #edit-bar .slot canvas { width: 42px; height: 42px; }
  #edit-bar .hint { font-size: 12px; padding: 0 4px; white-space: normal; max-width: 120px; }
  #btn-interact { font-size: 16px; padding: 9px 18px; bottom: 74px; }
  #house-bar .pill { padding: 6px 10px; font-size: 14px; } #house-bar .btn { padding: 6px 12px; }
  .modal-card { padding: 12px; border-radius: 18px; }
}
@media (max-width: 560px) {
  .wardrobe { grid-template-columns: 1fr; }
  .wardrobe .preview { position: static; flex-direction: row; justify-content: center; }
  .wardrobe .preview canvas { width: 130px; height: 154px; }
}
