/* MAI AN TIÊM – giao diện trong game (HTML phủ trên canvas) */
:root {
  --ink: #2b2118; --paper: #fffaf0; --paper2: #f3e6c8; --wood: #5e3b24; --wood2: #8f5f34;
  --bronze: #c9933e; --bronze2: #f0c870; --ok: #3f9442; --err: #c0433a;
  --font: "VT323", "Segoe UI", system-ui, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #174a75; touch-action: none; -webkit-user-select: none; user-select: none; }
body { font: 20px/1.15 var(--font); color: var(--ink); }
#game, #game canvas { position: fixed; inset: 0; }
#game canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#night { position: fixed; inset: 0; background: #1b2350; mix-blend-mode: multiply; opacity: 0; pointer-events: none; transition: opacity .5s linear; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
#ui [hidden] { display: none !important; }
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }

.ui-btn {
  font: inherit; font-size: 20px; min-width: 44px; min-height: 44px; padding: 4px 12px;
  border: 3px solid var(--wood); border-radius: 8px; background: var(--bronze2); color: var(--ink); cursor: pointer;
  box-shadow: inset 0 -3px 0 var(--bronze);
}
.ui-btn:active { transform: translateY(1px); box-shadow: none; }
.ui-btn:disabled { opacity: .45; cursor: not-allowed; }
.ui-btn.wide { width: 100%; }
.ui-btn.danger { background: #f0b7ae; }
.hint { color: #6b5a48; font-size: 18px; }

/* HUD */
.hud { position: absolute; left: 8px; top: 8px; display: grid; gap: 6px; max-width: min(340px, 60vw); pointer-events: none !important; }
.hud-time, .bar, .quest, .money, .target-hint {
  background: rgb(43 33 24 / 78%); color: #fffaf0; border: 2px solid var(--bronze); border-radius: 8px; padding: 2px 10px;
}
.hud-time { font-size: 22px; justify-self: start; }
.bar { position: relative; width: 200px; height: 24px; padding: 0; overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: #e8b23a; transition: width .2s; }
.bar-fill.low { background: #c0433a; }
.bar-text { position: relative; padding-left: 8px; font-size: 18px; text-shadow: 1px 1px 0 #1e1a24; }
.quest { font-size: 18px; display: grid; gap: 4px; }
.quest-title { color: var(--bronze2); }
.quest-item.side .quest-title { color: #9fd6e8; }
.obj.done { color: #a8d86a; }
.top-right { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; align-items: center; }
.money { font-size: 22px; padding: 6px 10px; }
.target-hint { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); font-size: 20px; white-space: nowrap; pointer-events: none !important; }

/* thanh công cụ */
.hotbar { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; background: rgb(43 33 24 / 78%); border: 2px solid var(--bronze); border-radius: 10px; }
.slot { position: relative; width: clamp(34px, 9vw, 52px); height: clamp(34px, 9vw, 52px); padding: 0; border: 2px solid #8f5f34; border-radius: 6px; background: #f3e6c8; cursor: pointer; display: grid; place-items: center; font: inherit; }
.slot img { width: 80%; height: 80%; }
.slot.sel { border-color: #fff; box-shadow: 0 0 0 3px var(--bronze2); }
.slot .key { position: absolute; left: 2px; top: -2px; font-size: 14px; color: #6b5a48; }
.slot .qty { position: absolute; right: 2px; bottom: -2px; font-size: 16px; color: #1e1a24; text-shadow: 1px 1px 0 #fffaf0; }
.slot .qty.water { left: 2px; right: auto; color: #1f6f9e; }
.noicon { color: #6b5a48; }

/* thông báo, hội thoại */
.toasts { position: absolute; left: 50%; top: 56px; transform: translateX(-50%); display: grid; gap: 4px; justify-items: center; pointer-events: none !important; }
.toast { background: rgb(255 250 240 / 95%); border: 2px solid var(--wood); border-radius: 8px; padding: 2px 12px; font-size: 20px; }
.toast.ok { border-color: var(--ok); }
.toast.warn { border-color: var(--err); }
.dialogue { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); width: min(680px, calc(100vw - 24px)); display: flex; gap: 12px; align-items: flex-start; background: var(--paper); border: 4px solid var(--wood); border-radius: 12px; padding: 10px 16px 6px; cursor: pointer; box-shadow: 0 6px 0 rgb(0 0 0 / 25%); }
.dialogue.system { background: #f3e6c8; }
.dialogue .portrait { flex: none; width: 72px; height: 72px; background: #e6d6b2; border: 3px solid var(--wood2); border-radius: 8px; }
.dialogue .dlg-body { flex: 1; min-width: 0; }
.dialogue .who { color: #8e6129; font-size: 22px; }
.dialogue .line { font-size: 24px; margin: 2px 0 4px; }
.dialogue .more { text-align: right; font-size: 16px; color: #6b5a48; }
.choices { display: grid; gap: 6px; margin: 4px 0 6px; }
.choice { font: inherit; font-size: 21px; text-align: left; padding: 6px 10px; min-height: 44px; border: 3px solid var(--wood2); border-radius: 8px; background: var(--paper2); color: var(--ink); cursor: pointer; }
.choice:hover, .choice:focus-visible { background: var(--bronze2); }

/* tên bản đồ / chương, mưa */
.banner { position: absolute; left: 50%; top: 28%; transform: translateX(-50%); text-align: center; pointer-events: none !important; color: #fffaf0; text-shadow: 2px 2px 0 #1e1a24, -1px -1px 0 #1e1a24; animation: banner-in .5s ease-out; }
.banner-title { font-size: 48px; }
.banner-sub { font-size: 26px; color: var(--bronze2); }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.rain { position: absolute; inset: 0; pointer-events: none !important; background-image: repeating-linear-gradient(105deg, transparent 0 14px, rgb(200 225 255 / 35%) 14px 15px, transparent 15px 31px); background-size: 120px 120px; animation: rain-fall .5s linear infinite; }
@keyframes rain-fall { from { background-position: 0 0; } to { background-position: -30px 120px; } }
@media (prefers-reduced-motion: reduce) { .rain { animation: none; } .banner { animation: none; } }

/* bảng */
.panel-wrap { position: absolute; inset: 0; background: rgb(20 14 8 / 45%); display: grid; place-items: center; padding: 8px; }
.panel { width: min(560px, 100%); max-height: calc(100vh - 16px); overflow: auto; background: var(--paper); border: 4px solid var(--wood); border-radius: 12px; padding: 10px 14px 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { margin: 0; font-size: 30px; font-weight: normal; }
.panel h3 { margin: 12px 0 6px; font-size: 24px; font-weight: normal; color: #8e6129; }
.bag { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.bag .slot { width: 100%; height: auto; aspect-ratio: 1; }
.bag .slot.extra { background: #e6d6b2; }
.detail { background: var(--paper2); border-radius: 8px; padding: 8px 10px; }
.detail p { margin: 4px 0 8px; }
.craft { display: grid; gap: 6px; }
.recipe { display: grid; grid-template-columns: 40px 1fr auto; gap: 8px; align-items: center; background: var(--paper2); border-radius: 8px; padding: 4px 8px; }
.recipe img { width: 40px; height: 40px; }
.recipe.off { opacity: .75; }
.menu { display: grid; gap: 8px; margin: 10px 0; }
.keys { margin: 0; padding-left: 20px; font-size: 18px; }

/* cảm ứng */
.touch { position: absolute; inset: auto 0 0 0; height: 0; }
.stick { position: absolute; left: 18px; bottom: 76px; width: 130px; height: 130px; border-radius: 50%; background: rgb(255 250 240 / 22%); border: 3px solid rgb(255 250 240 / 55%); touch-action: none; }
.knob { position: absolute; left: 35px; top: 35px; width: 60px; height: 60px; border-radius: 50%; background: rgb(255 250 240 / 70%); border: 3px solid var(--wood); }
.acts { position: absolute; right: 16px; bottom: 80px; display: grid; gap: 12px; }
.act { width: 76px; height: 76px; border-radius: 50%; font: inherit; font-size: 24px; border: 4px solid var(--wood); background: var(--bronze2); touch-action: none; }
.act.hand { background: #a8d86a; }
@media (hover: hover) and (pointer: fine) { .touch, .touch-only { display: none; } }

/* màn hình bắt đầu, tải */
.title, .loading { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 30%, #5fd0d8, #1f6f9e 60%, #174a75); padding: 12px; }
.title-card { width: min(520px, 100%); background: var(--paper); border: 4px solid var(--wood); border-radius: 14px; padding: 14px 18px; text-align: center; }
.title-card h1 { margin: 0; font-size: 56px; font-weight: normal; color: #8e6129; letter-spacing: 1px; }
.title-card .sub { margin: 0 0 10px; font-size: 22px; }
.slots { display: grid; gap: 8px; text-align: left; }
.save-slot { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; background: var(--paper2); border-radius: 8px; padding: 6px 10px; }
.loading .box { width: min(360px, 90%); color: #fffaf0; text-align: center; font-size: 24px; }
.loading .track { height: 16px; border: 3px solid #fffaf0; border-radius: 8px; margin-top: 8px; overflow: hidden; }
.loading .fill { height: 100%; width: 0; background: var(--bronze2); }

/* tài khoản ở màn bắt đầu */
.title { overflow-y: auto; touch-action: pan-y; }
.title input, .title textarea { -webkit-user-select: text; user-select: text; touch-action: manipulation; }
.acc-bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; margin: 4px 0 8px; }
.acc-name { font-size: 22px; color: #8e6129; }
.acc-form { display: grid; gap: 8px; text-align: left; }
.acc-form h2 { margin: 0; font-size: 30px; font-weight: normal; color: #8e6129; }
.acc-form h3 { margin: 8px 0 0; font-size: 24px; font-weight: normal; }
.danger-zone { border-top: 2px dashed #e0b8a8; margin-top: 10px; padding-top: 6px; }
.field { display: grid; gap: 2px; font-size: 18px; color: #6b5a48; }
.input { font: 20px/1.2 "Segoe UI", system-ui, sans-serif; padding: 8px 10px; min-height: 44px; border: 3px solid var(--wood2); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
.input:focus-visible, .link:focus-visible, .choice:focus-visible, .ui-btn:focus-visible { outline: 3px solid #1f6f9e; outline-offset: 2px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ui-btn.primary { background: var(--wood); color: #fffaf0; box-shadow: inset 0 -3px 0 #3a2416; }
.link { font: inherit; font-size: 18px; background: none; border: 0; color: #1f6f9e; text-decoration: underline; cursor: pointer; justify-self: start; padding: 4px 0; min-height: 36px; }
.code { font: 26px/1.3 Consolas, "Courier New", monospace; letter-spacing: 2px; text-align: center; padding: 10px; background: #fff; border: 3px dashed var(--bronze); border-radius: 8px; -webkit-user-select: all; user-select: all; }
.check { display: flex; gap: 8px; align-items: center; font-size: 20px; }
.check input { width: 24px; height: 24px; }
.form-msg { margin: 0; padding: 6px 10px; border-radius: 8px; font-size: 18px; background: #f3e6c8; }
.form-msg.err { background: #f6d3cf; color: #8b1d16; }
.form-msg.ok { background: #dcefdc; color: #24632a; }
.hint.warn { color: #a3401f; }

/* điện thoại cầm dọc khi đang chơi: nhắc xoay ngang */
#rotate { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; align-content: center; gap: 12px; text-align: center; padding: 24px; background: #174a75; color: #fffaf0; font-size: 26px; }
#rotate .big { font-size: 64px; line-height: 1; margin-bottom: 8px; }
@media (pointer: coarse) and (orientation: portrait) { body.in-game #rotate { display: grid; } }

/* điện thoại nằm ngang (màn thấp): thu gọn HUD, nút đặt hai bên */
@media (orientation: landscape) and (max-height: 500px) {
  body { font-size: 17px; }
  .hud { left: 6px; top: 6px; gap: 4px; max-width: min(300px, 38vw); }
  .hud-time { font-size: 18px; }
  .bar { width: 130px; height: 20px; }
  .bar-text { font-size: 15px; }
  .quest { font-size: 15px; max-height: 42vh; overflow: hidden; }
  .top-right { right: 6px; top: 6px; }
  .money { font-size: 18px; padding: 2px 8px; }
  .ui-btn { min-height: 40px; min-width: 40px; font-size: 18px; }
  .hotbar { bottom: 4px; gap: 3px; padding: 3px; }
  .slot { width: 38px; height: 38px; }
  .slot .key { font-size: 12px; }
  .target-hint { bottom: 52px; font-size: 17px; max-width: calc(100vw - 300px); overflow: hidden; text-overflow: ellipsis; }
  .toasts { top: 6px; }
  .toast { font-size: 17px; }
  .stick { left: 16px; bottom: 16px; width: 112px; height: 112px; }
  .knob { left: 28px; top: 28px; width: 50px; height: 50px; }
  .acts { right: 16px; bottom: 16px; gap: 10px; }
  .act { width: 66px; height: 66px; font-size: 20px; }
  .dialogue { bottom: 58px; width: min(600px, calc(100vw - 300px)); max-height: 56vh; overflow: auto; padding: 6px 10px 4px; }
  .dialogue .portrait { width: 48px; height: 48px; }
  .dialogue .line { font-size: 20px; }
  .dialogue .who { font-size: 18px; }
  .choice { font-size: 18px; min-height: 40px; }
  .banner { top: 16%; }
  .banner-title { font-size: 34px; }
  .banner-sub { font-size: 20px; }
  .panel { max-height: calc(100vh - 12px); padding: 6px 10px 10px; }
  .panel h2 { font-size: 24px; }
  .bag { grid-template-columns: repeat(8, 1fr); }
  .title { place-items: start center; }
  .title-card { padding: 8px 14px; }
  .title-card h1 { font-size: 40px; }
}
@media (orientation: landscape) and (max-height: 500px) and (pointer: fine) { .dialogue { width: min(640px, calc(100vw - 24px)); } .target-hint { max-width: none; } }

@media (max-width: 560px) {
  body { font-size: 18px; }
  .bar { width: 150px; }
  .hud { max-width: 58vw; }
  .quest { font-size: 16px; }
  .banner-title { font-size: 36px; }
  .banner-sub { font-size: 20px; }
  .dialogue { bottom: 200px; }
  .dialogue .portrait { width: 52px; height: 52px; }
  .dialogue .line { font-size: 21px; }
  .stick { width: 110px; height: 110px; bottom: 70px; }
  .knob { left: 27px; top: 27px; width: 50px; height: 50px; }
  .act { width: 64px; height: 64px; font-size: 20px; }
}
