:root {
  --ink: #241813;
  --kraft: #d29b59;
  --kraft-light: #efc77f;
  --kraft-dark: #70421f;
  --paper: #fff2cf;
  --red: #b94338;
  --blue: #397db0;
  --gold: #f4bd38;
  --shadow: rgba(35, 19, 12, .42);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
  background: #241813;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body { min-height: 100vh; overflow-x: hidden; background: #241813; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: #2a1a13;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  opacity: .1;
  mix-blend-mode: multiply;
  background-image: radial-gradient(rgba(255,255,255,.32) 0.7px, transparent .7px), radial-gradient(rgba(0,0,0,.28) .6px, transparent .6px);
  background-position: 0 0, 12px 8px;
  background-size: 19px 19px, 27px 27px;
}

.login-screen, .teacher-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 18%, #6f4b31 0, #352219 43%, #1e120e 100%);
}

.login-wrap { width: min(980px, 100%); display: grid; grid-template-columns: 1.05fr .95fr; gap: 24px; align-items: stretch; }
.brand-card, .login-card, .teacher-card {
  position: relative;
  border: 4px solid var(--ink);
  box-shadow: 0 14px 0 rgba(0,0,0,.22), 0 18px 32px rgba(0,0,0,.24);
  background: var(--paper);
  clip-path: polygon(1% 2%, 98% 0, 100% 97%, 2% 100%);
}
.brand-card { min-height: 520px; padding: 48px 42px; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(135deg, #c88a4a, #f4cd82 44%, #bb753d); }
.brand-card h1 { margin: 0; font-size: clamp(3.2rem, 8vw, 6.7rem); line-height: .84; letter-spacing: -.08em; text-shadow: 4px 4px 0 #f5d38e; }
.brand-card p { max-width: 390px; font-size: 1.25rem; line-height: 1.4; font-weight: 800; }
.paper-star { color: var(--gold); text-shadow: 2px 2px 0 var(--ink); font-size: 3.4rem; transform: rotate(-11deg); align-self: flex-end; }
.login-card { padding: 28px; }
.login-card h2, .teacher-card h2 { margin: 4px 0 8px; font-size: 2rem; }
.login-card p { margin-top: 0; opacity: .76; }
.role-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 20px 0; }
.toggle-button, .wood-button, .soft-button, .room-arrow, .close-button {
  border: 3px solid var(--ink);
  color: var(--ink);
  background: var(--kraft-light);
  box-shadow: 0 4px 0 var(--kraft-dark);
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.toggle-button { padding: 11px 9px; font-weight: 900; background: #e6d5aa; }
.toggle-button.active { background: var(--gold); transform: translateY(-2px); }
.wood-button, .soft-button { padding: 12px 18px; font-weight: 900; }
.wood-button.primary { background: var(--red); color: #fff6dc; }
.wood-button.blue { background: var(--blue); color: #fff6dc; }
.soft-button { background: #f7e5bb; box-shadow: 0 3px 0 #9e7447; }
.toggle-button:hover, .wood-button:hover, .soft-button:hover, .room-arrow:hover, .close-button:hover { transform: translateY(-2px) rotate(-.4deg); filter: brightness(1.05); }
.toggle-button:active, .wood-button:active, .soft-button:active, .room-arrow:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--kraft-dark); }
.form-stack { display: grid; gap: 12px; }
.form-stack label { display: grid; gap: 5px; font-weight: 900; }
.form-stack input, .profile-form input { width: 100%; border: 3px solid var(--ink); background: #fff9e8; padding: 11px 12px; outline: none; }
.form-stack input:focus, .profile-form input:focus { box-shadow: 0 0 0 4px rgba(244,189,56,.45); }
.form-error { min-height: 20px; color: #a12928; font-weight: 900; }
.small-link { border: 0; background: transparent; color: #2d5d7b; text-decoration: underline; padding: 0; font-weight: 900; }

.world-shell { min-height: 100vh; position: relative; background: #4d311e; }
.world-canvas { position: relative; width: 100vw; aspect-ratio: 1672 / 941; min-height: 100vh; max-height: 100vh; overflow: hidden; background: #4d311e; }
.world-background { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center; }
.world-shimmer { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 47%, transparent 0 27%, rgba(255,237,165,.1) 36%, transparent 62%), linear-gradient(115deg, transparent 0 33%, rgba(255,244,194,.13) 39%, transparent 45%); mix-blend-mode: screen; animation: breathe 7s ease-in-out infinite; }
.ambient { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ambient::before, .ambient::after { content: ""; position: absolute; width: 7px; height: 7px; border-radius: 50%; background: #f6d76e; box-shadow: 0 0 14px #f6d76e, 42vw 9vh 0 1px #f5c76a, 81vw 48vh 0 0 #f5c76a, 18vw 67vh 0 1px #f5c76a; animation: dust 9s linear infinite; opacity: .7; }
.ambient::after { animation-delay: -4.2s; transform: scale(.7); opacity: .4; }

.hud { position: absolute; z-index: 12; top: 16px; left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.hud-chip { min-height: 48px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border: 3px solid var(--ink); background: rgba(255,239,196,.95); box-shadow: 0 5px 0 rgba(82,41,20,.72); font-weight: 900; clip-path: polygon(2% 6%, 96% 0, 100% 92%, 0 100%); }
.hud-chip strong { font-size: 1.15rem; }
.hud-avatar { width: 42px; height: 42px; position: relative; flex: 0 0 auto; }
.mini-avatar { display: block; position: relative; width: 42px; height: 42px; }
.mini-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.hud-button { border: 3px solid var(--ink); padding: 11px 13px; background: #f7d57b; font-weight: 900; box-shadow: 0 4px 0 var(--kraft-dark); }
.hud-button:hover { transform: translateY(-2px); }

.hotspot { position: absolute; z-index: 8; border: 0; background: transparent; transform: translate(-50%, -50%); padding: 0; }
.hotspot .marker { display: grid; place-items: center; min-width: 82px; min-height: 48px; padding: 8px 12px; border: 3px solid var(--ink); background: rgba(255,238,190,.94); box-shadow: 0 5px 0 rgba(67,35,20,.6); clip-path: polygon(4% 6%, 97% 0, 100% 92%, 0 100%); font-weight: 900; color: var(--ink); transition: transform .2s ease; }
.hotspot .marker small { display: block; font-size: .72rem; opacity: .7; }
.hotspot:hover .marker { transform: translateY(-7px) rotate(-2deg) scale(1.05); }
.hotspot .pulse { position: absolute; inset: -10px; border: 2px dashed rgba(255,245,183,.9); opacity: 0; animation: pulse 3s ease-out infinite; }
.hotspot-shop { left: 50%; top: 55%; }
.hotspot-space { left: 49%; top: 11%; }
.hotspot-castle { left: 72%; top: 18%; }
.hotspot-haunted { left: 15%; top: 48%; }
.hotspot-zombie { left: 16%; top: 15%; }
.hotspot-spooky { left: 13%; top: 49%; }
.hotspot-fair { left: 87%; top: 44%; }
.hotspot-lava { left: 27%; top: 85%; }
.hotspot-caterpillar { left: 84%; top: 72%; }
.hotspot-moles { left: 70%; top: 84%; }

.room-shell { min-height: 100vh; position: relative; overflow: hidden; background: #4d311e; }
.room-scene { position: relative; width: 100vw; min-height: 100vh; aspect-ratio: 1672 / 941; overflow: hidden; background: #5e3b23; }
.room-background { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.room-overlay { position: absolute; inset: 0; z-index: 4; pointer-events: none; background: radial-gradient(circle at 50% 42%, transparent 0 22%, rgba(255,225,135,.08) 43%, rgba(31,15,8,.14) 100%); }
.room-overlay::after { content: ""; position: absolute; inset: -20%; background: linear-gradient(112deg, transparent 25%, rgba(255,245,198,.13) 37%, transparent 46%); animation: lightSweep 11s ease-in-out infinite; }
.room-content { position: absolute; inset: 0; z-index: 8; }
.room-nav { position: absolute; z-index: 14; top: 50%; left: 14px; right: 14px; transform: translateY(-50%); display: flex; justify-content: space-between; pointer-events: none; }
.room-arrow { pointer-events: auto; width: 58px; height: 62px; font-size: 2rem; background: rgba(247,213,123,.92); clip-path: polygon(10% 4%, 92% 0, 100% 90%, 3% 100%); }
.room-arrow[disabled] { opacity: .25; pointer-events: none; }
.room-label { position: absolute; top: 92px; left: 50%; transform: translateX(-50%); padding: 9px 22px; z-index: 11; border: 3px solid var(--ink); background: rgba(255,240,197,.9); font-weight: 1000; box-shadow: 0 4px 0 rgba(57,28,14,.5); clip-path: polygon(2% 5%, 98% 0, 100% 91%, 0 100%); }
.avatar-stage { position: absolute; left: 50%; top: 54%; width: min(29vw, 360px); aspect-ratio: 1; transform: translate(-50%, -50%); display: grid; place-items: center; pointer-events: none; }
.avatar-stage::before { content: ""; position: absolute; width: 75%; height: 16%; bottom: 5%; border-radius: 50%; background: rgba(52,25,13,.3); filter: blur(8px); }
.avatar-stage .avatar-layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(10px 10px 0 rgba(54,25,14,.24)); }
.avatar-stage .avatar-layer.base { animation: avatarFloat 4.5s ease-in-out infinite; }
.avatar-stage.shop-avatar { top: 52%; width: min(24vw, 310px); }
.avatar-stage.dressing-avatar { top: 53%; width: min(31vw, 390px); }
.avatar-stage.treasure-avatar { top: 48%; left: 23%; width: min(20vw, 250px); }
.room-panel { position: absolute; z-index: 10; border: 3px solid var(--ink); background: rgba(255,242,207,.94); box-shadow: 0 8px 0 rgba(51,23,11,.38); clip-path: polygon(1% 2%, 98% 0, 100% 97%, 2% 100%); pointer-events: auto; }
.shop-panel { right: 5.8%; bottom: 7%; width: min(31vw, 450px); padding: 14px; }
.dressing-panel { right: 4%; bottom: 7%; width: min(33vw, 500px); padding: 14px; }
.treasure-panel { right: 7%; top: 27%; width: min(37vw, 560px); padding: 15px; }
.panel-title { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 9px; font-weight: 1000; }
.panel-title span { opacity: .68; font-size: .82rem; }
.category-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 7px; scrollbar-width: thin; }
.category-button { border: 2px solid var(--ink); background: #edd19a; padding: 7px 9px; font-size: .78rem; font-weight: 900; white-space: nowrap; }
.category-button.active { background: var(--gold); }
.item-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-height: 240px; overflow-y: auto; padding: 4px; }
.item-card { position: relative; min-height: 89px; border: 3px solid var(--ink); background: #fff7de; box-shadow: 0 3px 0 #a47342; display: grid; place-items: center; padding: 5px; cursor: pointer; }
.item-card:hover, .item-card.selected { transform: translateY(-3px) rotate(-1deg); background: #ffeab0; }
.item-card.selected { outline: 3px solid var(--gold); outline-offset: 2px; }
.item-card img { width: 100%; height: 68px; object-fit: contain; }
.item-card .price { position: absolute; right: 3px; bottom: 2px; font-size: .65rem; font-weight: 1000; background: #f3c54b; padding: 2px 4px; }
.item-card.owned .price { background: #75bd72; }
.item-card.locked { filter: saturate(.25); }
.item-card.locked::after { content: "🔒"; position: absolute; top: 4px; left: 5px; font-size: .84rem; }
.shop-actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; }
.preview-caption { font-size: .78rem; opacity: .72; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-tile { border: 3px solid var(--ink); background: #ffe8aa; padding: 12px; box-shadow: 0 4px 0 #9a6935; }
.stat-tile strong { display: block; font-size: 1.6rem; margin-top: 3px; }
.progress-line { height: 12px; border: 2px solid var(--ink); background: #f5e2b2; margin-top: 7px; overflow: hidden; }
.progress-line i { display: block; height: 100%; width: 62%; background: var(--blue); }
.treasure-note { margin: 12px 0 0; font-size: .8rem; opacity: .7; }
.achievement-strip { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.achievement { border: 2px solid var(--ink); background: #fff3c8; padding: 7px 9px; font-size: .78rem; font-weight: 900; }
.room-help { position: absolute; left: 50%; bottom: 25px; transform: translateX(-50%); z-index: 9; padding: 8px 13px; background: rgba(255,242,207,.86); border: 2px solid var(--ink); font-size: .78rem; font-weight: 900; }

.teacher-screen { display: block; padding: 0; background: radial-gradient(circle at 50% 0, #b87c43, #352016 72%); }
.teacher-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 20px 24px; }
.teacher-top h1 { margin: 0; color: #fff2cf; text-shadow: 3px 3px 0 #3f2116; }
.teacher-layout { width: min(1180px, calc(100% - 48px)); margin: 0 auto 40px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 22px; }
.teacher-card { padding: 23px; }
.teacher-card h3 { margin: 0 0 13px; }
.teacher-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 22px; }
.kpi { border: 3px solid var(--ink); background: #fbe3a9; padding: 12px; box-shadow: 0 4px 0 #9e7040; }
.kpi strong { display: block; font-size: 1.75rem; }
.profile-list { display: grid; gap: 10px; }
.profile-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 3px solid var(--ink); padding: 11px; background: #fff3cc; }
.profile-row strong { display: block; }
.profile-row small { opacity: .68; }
.profile-form { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: end; }
.profile-form label { font-weight: 900; font-size: .8rem; }
.profile-form button { height: 47px; }
.teacher-note { border-left: 6px solid var(--gold); padding-left: 12px; line-height: 1.45; }

.modal-layer { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 22px; background: rgba(24,12,7,.64); backdrop-filter: blur(4px); }
.modal-card { width: min(520px, 100%); padding: 24px; border: 4px solid var(--ink); background: var(--paper); box-shadow: 0 12px 0 #3b2013; clip-path: polygon(1% 2%, 98% 0, 100% 97%, 2% 100%); }
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 17px; }
.close-button { float: right; width: 34px; height: 34px; background: #f3cf8a; }
.choice-grid { display: grid; gap: 10px; }
.choice-button { display: flex; align-items: center; gap: 12px; text-align: left; border: 3px solid var(--ink); background: #fff6da; padding: 13px; box-shadow: 0 4px 0 #9b6e42; font-weight: 900; }
.choice-button:hover { transform: translateY(-2px); background: #ffe7a3; }
.toast { position: fixed; z-index: 100; right: 20px; bottom: 20px; border: 3px solid var(--ink); padding: 13px 17px; background: #ffe18b; box-shadow: 0 5px 0 #8b5d33; font-weight: 1000; animation: toastIn .28s ease-out; }
.screen-transition { animation: roomIn .45s ease both; }
.shop-particles { position: absolute; inset: 0; pointer-events: none; z-index: 13; overflow: hidden; }
.coin-particle { position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #8f5e16; background: #f5c534; animation: coinFly 1s ease-in forwards; }

@keyframes avatarFloat { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }
@keyframes breathe { 0%,100% { opacity: .65; transform: scale(1); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes lightSweep { 0%,100% { transform: translateX(-8%); opacity: .2; } 50% { transform: translateX(8%); opacity: .55; } }
@keyframes dust { 0% { transform: translate(0, 100vh); opacity: 0; } 25% { opacity: .7; } 100% { transform: translate(18vw, -10vh); opacity: 0; } }
@keyframes pulse { 0% { transform: scale(.7); opacity: 0; } 20% { opacity: .8; } 100% { transform: scale(1.28); opacity: 0; } }
@keyframes roomIn { from { opacity: 0; transform: translateX(25px) scale(1.015); } to { opacity: 1; transform: translateX(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) rotate(2deg); } to { opacity: 1; transform: translateY(0) rotate(0); } }
@keyframes coinFly { 0% { transform: translate(0,0) scale(1); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(.45) rotate(480deg); opacity: 0; } }

@media (max-width: 900px) {
  .login-wrap, .teacher-layout { grid-template-columns: 1fr; }
  .brand-card { min-height: 300px; }
  .room-panel { width: min(90vw, 500px); right: 50%; transform: translateX(50%); bottom: 4%; }
  .treasure-panel { top: auto; bottom: 4%; }
  .avatar-stage, .avatar-stage.dressing-avatar { width: min(42vw, 290px); top: 42%; }
  .avatar-stage.treasure-avatar { left: 27%; top: 37%; width: min(25vw, 190px); }
  .room-label { top: 84px; }
  .room-help { display: none; }
}
@media (max-width: 600px) {
  .hud { top: 8px; left: 8px; right: 8px; }
  .hud-chip { min-height: 39px; padding: 5px 8px; font-size: .75rem; }
  .hud-chip strong { font-size: .95rem; }
  .hud-button { padding: 8px; }
  .hotspot .marker { min-width: 56px; min-height: 35px; font-size: .68rem; padding: 5px 7px; }
  .hotspot .marker small { font-size: .54rem; }
  .hotspot-shop { left: 50%; top: 53%; }
  .room-panel { max-height: 37vh; overflow: auto; }
  .item-grid { max-height: 120px; grid-template-columns: repeat(4, 1fr); }
  .item-card { min-height: 63px; }
  .item-card img { height: 45px; }
  .room-arrow { width: 43px; height: 48px; font-size: 1.4rem; }
  .room-nav { left: 7px; right: 7px; }
  .teacher-top { padding: 14px; }
  .teacher-layout { width: calc(100% - 24px); }
  .teacher-kpis { grid-template-columns: 1fr; }
  .profile-form { grid-template-columns: 1fr 100px; }
  .profile-form button { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
