/* Ruin World — cổng đăng nhập bằng ví. Màu + font lấy từ UiKit của game (Cream, Gold, GoldDeep, Ink, Interior).
   Mọi thứ nằm trong .rw-gate (một lớp phủ kín màn hình, đè lên canvas Unity) — không đụng tới html / body của trang chủ quản. */
@font-face { font-family: "RuinPixel"; src: url("../game-font.woff2") format("woff2"); font-display: swap; }

.rw-gate {
  --cream: #F4E4C4; --gold: #FFD27A; --gold-deep: #D9A04A; --muted: #B8A390; --ink: #2E1E22;
  --interior: #3A2C36; --outline: #1d1210; --good: #9BE27E; --bad: #FF8270;
  --panel: rgba(22, 24, 16, .84); --line: rgba(217, 160, 74, .55);
  --sea: 54 84 124; --shade: 18 30 48; /* màu nền ngoài cùng + màu lớp tối sau chữ — login.js đặt lại theo kiểu cảnh đang chọn */
  position: absolute; top: 0; left: 0; right: 0; height: var(--app-h, 100%); z-index: 5; overflow: hidden;
  background: rgb(var(--sea)); font-family: "RuinPixel", ui-monospace, "Courier New", monospace; color: var(--cream); line-height: 1.35;
  -webkit-tap-highlight-color: transparent; transition: opacity .45s ease;
}
.rw-gate[hidden] { display: none; }
.rw-gate.is-leaving { opacity: 0; pointer-events: none; } /* vào game: mờ dần rồi ẩn hẳn */
.rw-gate, .rw-gate * { box-sizing: border-box; }
.rw-gate :where(button, input) { font: inherit; color: inherit; } /* :where ⇒ không thắng luật màu / cỡ chữ riêng của từng nút */
.rw-gate :where(button) { cursor: pointer; }
.rw-gate :focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ── Nền ── */
.rw-scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .9s ease; }
.rw-scene.is-ready { opacity: 1; }
.rw-shade { position: absolute; inset: 0; pointer-events: none; /* màn dọc: tối thêm sau logo (trên) và nút (dưới) */
  background: linear-gradient(rgb(var(--shade) / .82) 0, rgb(var(--shade) / .45) 22%, rgba(12, 16, 42, 0) 34%, rgba(12, 16, 42, 0) 66%, rgb(var(--shade) / .55) 80%, rgb(var(--shade) / .92) 100%); }

/* ── Góc trên: ngôn ngữ ── */
.rw-top { position: absolute; z-index: 2; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
          display: flex; padding: 3px; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.rw-lang { min-width: 46px; height: 38px; padding: 0 10px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 16px; }
.rw-lang[aria-pressed="true"] { background: rgba(217, 160, 74, .22); color: var(--gold); }
.rw-lang:hover { color: var(--cream); }

.rw-pick { position: absolute; z-index: 2; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left));
           display: flex; padding: 3px; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.rw-pick .rw-lang { min-width: 38px; font-size: 20px; color: var(--gold); }
.rw-pick-name { align-self: center; min-width: 176px; padding: 0 6px; text-align: center; font-size: 15px; color: var(--cream); white-space: pre; }

/* ── Khối giữa ── */
/* Mặc định (màn dọc): logo ở trên, nút ở dưới, thành nằm giữa. Màn ngang đổi thành hai cột — xem cuối file. */
.rw-hero { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
           padding: max(50px, 7.5vh) 20px calc(92px + env(safe-area-inset-bottom)); text-align: center; pointer-events: none; }
.rw-hero > * { pointer-events: auto; }
.rw-brand { display: flex; flex-direction: column; align-items: center; }
.rw-logo { margin: 0; display: flex; flex-direction: column; align-items: center; font-weight: normal; line-height: .86; letter-spacing: .02em;
           font-size: clamp(50px, min(19vw, 10.5vh), 120px); user-select: none; }
.rw-word { position: relative; display: inline-block; isolation: isolate; }
.rw-word::before { /* lớp viền + bóng đổ cứng kiểu pixel, nằm sau lớp tô màu */
  content: attr(data-text); position: absolute; inset: 0; z-index: -1; color: var(--outline);
  text-shadow: -.05em 0 0 var(--outline), .05em 0 0 var(--outline), 0 -.05em 0 var(--outline), 0 .05em 0 var(--outline),
               -.04em -.04em 0 var(--outline), .04em -.04em 0 var(--outline), -.04em .04em 0 var(--outline), .04em .04em 0 var(--outline),
               0 .12em 0 var(--outline), -.045em .11em 0 var(--outline), .045em .11em 0 var(--outline), 0 .2em .32em rgba(0, 0, 0, .6); }
.rw-fill { display: inline-block; color: var(--gold); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
           background-image: linear-gradient(#FFF4D2 0 30%, #FFD27A 30% 62%, #E79A3C 62% 82%, #B9692A 82% 100%); }
.rw-world { display: flex; align-items: center; gap: .32em; margin-top: .2em; font-size: .4em; letter-spacing: .3em; }
.rw-world .rw-word { margin-right: -.3em; } /* bù khoảng giãn chữ cuối để cân giữa */
.rw-world .rw-fill { background-image: linear-gradient(#FFFFFF 0 34%, #F4E4C4 34% 70%, #CFB58A 70% 100%); }
.rw-rule { flex: none; width: 1.35em; height: .1em; background: var(--gold-deep); box-shadow: 0 0 0 .05em var(--outline); }

.rw-tag { max-width: 560px; text-wrap: balance; margin: clamp(10px, 2.4vh, 26px) 0 0; font-size: clamp(19px, 2.5vh + 6px, 28px); color: var(--cream);
          text-shadow: 0 2px 0 var(--outline), 0 0 14px rgba(0, 0, 0, .7); }
.rw-sub { margin: 6px 0 0; font-size: clamp(12px, min(3.45vw, 1.2vh + 7px), 17px); letter-spacing: .06em; color: var(--gold); white-space: nowrap;
          text-shadow: 0 2px 0 var(--outline), 0 0 12px rgba(0, 0, 0, .7); }

.rw-action { display: flex; flex-direction: column; align-items: center; width: 100%; }
.rw-cta { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 12px;
          min-width: min(100%, 300px); min-height: 64px; padding: 10px 30px 14px; font-size: 25px; color: var(--ink);
          border: 3px solid var(--outline); border-radius: 7px;
          background: linear-gradient(#FFE7A6 0 48%, #F4C766 48% 100%);
          box-shadow: inset 0 3px 0 #FFF6D6, inset 0 -6px 0 #C98A38, 0 5px 0 var(--outline), 0 12px 26px rgba(0, 0, 0, .5);
          transition: transform .08s ease, filter .12s ease, box-shadow .08s ease; }
.rw-cta:hover { filter: brightness(1.06); transform: translateY(-1px); }
.rw-cta:active { transform: translateY(4px); box-shadow: inset 0 3px 0 #FFF6D6, inset 0 -3px 0 #C98A38, 0 1px 0 var(--outline), 0 5px 12px rgba(0, 0, 0, .5); }
.rw-cta:focus-visible { outline-color: var(--cream); outline-offset: 5px; }
.rw-cta svg { width: 26px; height: 26px; flex: none; }
.rw-cta.is-idle { animation: rw-breathe 2.8s ease-in-out infinite; }
@keyframes rw-breathe { 50% { filter: brightness(1.09); } }

.rw-hint { max-width: 460px; margin: 16px 0 0; font-size: 15px; text-wrap: balance; color: var(--cream); opacity: .92;
           text-shadow: 0 1px 0 var(--outline), 0 0 10px rgba(0, 0, 0, .8); }
.rw-account { margin-top: 14px; display: inline-flex; align-items: center; gap: 10px; padding: 5px 6px 5px 12px; font-size: 15px;
              background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.rw-account[hidden] { display: none; }
.rw-dot { width: 8px; height: 8px; background: var(--good); box-shadow: 0 0 0 2px rgba(155, 226, 126, .25); }
.rw-addr { color: var(--cream); letter-spacing: .04em; min-width: 0; text-align: left; }
.rw-hex::before { content: "· "; }
.rw-link { flex: none; white-space: nowrap; }
.rw-link { min-height: 34px; padding: 0 10px; border: 0; border-radius: 4px; background: rgba(217, 160, 74, .18); color: var(--gold); font-size: 15px; }
.rw-link:hover { background: rgba(217, 160, 74, .3); }

/* ── Chân trang ── */
.rw-foot { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; padding: 0 16px max(14px, env(safe-area-inset-bottom));
           display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 13px; color: var(--muted);
           text-shadow: 0 1px 0 var(--outline), 0 0 8px rgba(0, 0, 0, .8); pointer-events: none; }
.rw-foot > * { pointer-events: auto; }
.rw-safe { margin: 0; color: var(--cream); opacity: .9; text-wrap: balance; }
.rw-safe svg { width: 12px; height: 14px; margin-right: 6px; vertical-align: -2px; }
.rw-legal { margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; }
.rw-legal a { color: var(--muted); padding: 6px 2px; }
.rw-legal a:hover { color: var(--cream); }

.rw-toast { position: absolute; z-index: 3; left: 50%; bottom: max(84px, calc(env(safe-area-inset-bottom) + 84px)); transform: translate(-50%, 16px);
            max-width: min(92vw, 420px); padding: 10px 16px; font-size: 15px; text-align: center; color: var(--cream);
            background: var(--panel); border: 1px solid var(--line); border-radius: 6px; opacity: 0; pointer-events: none;
            transition: opacity .2s ease, transform .2s ease; }
.rw-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── Hộp chọn ví: khung tím sẫm + viền đồng + băng tiêu đề đỏ như cửa sổ trong game ── */
.rw-modal { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 20px;
            background: rgba(6, 8, 4, .68); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: rw-fade .16s ease; }
.rw-modal[hidden] { display: none; }
.rw-panel { width: min(100%, 420px); max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
            background: #2F242C; border: 2px solid var(--gold-deep); border-radius: 8px;
            box-shadow: 0 0 0 3px var(--outline), inset 0 0 0 2px rgba(0, 0, 0, .35), 0 24px 60px rgba(0, 0, 0, .6); animation: rw-rise .2s ease; }
.rw-title { display: flex; align-items: center; gap: 10px; margin: 8px 8px 0; padding: 4px 4px 4px 14px; min-height: 48px;
            background: linear-gradient(#7A2424 0 50%, #631B1B 50% 100%); border: 2px solid var(--outline); border-radius: 5px;
            box-shadow: inset 0 2px 0 rgba(255, 190, 150, .18); }
.rw-title h2 { flex: 1; margin: 0; font-size: 22px; font-weight: normal; color: var(--gold); text-shadow: 0 2px 0 var(--outline); text-align: left; }
.rw-x { flex: none; width: 44px; height: 40px; border: 0; border-radius: 4px; background: rgba(0, 0, 0, .25); color: var(--cream); font-size: 24px; line-height: 1; }
.rw-x:hover { background: rgba(0, 0, 0, .45); }
.rw-body { padding: 14px 16px 18px; overflow-y: auto; }
.rw-lead { margin: 0 0 12px; font-size: 15px; color: var(--muted); text-align: left; }
.rw-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rw-wallet { width: 100%; min-height: 60px; display: flex; align-items: center; gap: 14px; padding: 8px 14px 8px 10px; text-align: left;
             font-size: 19px; color: var(--cream); background: #3A2C36; border: 2px solid #56424F; border-radius: 6px;
             box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25); transition: border-color .12s, background .12s; }
.rw-wallet:hover, .rw-wallet:focus-visible { border-color: var(--gold-deep); background: #443340; }
.rw-wallet img, .rw-wallet svg { width: 38px; height: 38px; flex: none; border-radius: 6px; }
.rw-wallet span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rw-wallet em { flex: none; font-style: normal; font-size: 13px; color: var(--good); }
.rw-note { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid rgba(217, 160, 74, .25); font-size: 14px; color: var(--muted); text-align: left; }
.rw-note a { color: var(--gold); }
.rw-empty { padding: 4px 0 2px; text-align: left; }
.rw-empty h3 { margin: 0 0 8px; font-size: 19px; font-weight: normal; color: var(--cream); }
.rw-empty p { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.rw-step { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0 4px; text-align: center; }
.rw-step img, .rw-step > svg { width: 56px; height: 56px; border-radius: 8px; }
.rw-step h3 { margin: 4px 0 0; font-size: 21px; font-weight: normal; color: var(--cream); }
.rw-step p { margin: 0; max-width: 320px; font-size: 15px; color: var(--muted); }
.rw-step p.is-bad { color: var(--bad); }
.rw-spin { width: 28px; height: 28px; margin: 6px 0; border: 4px solid rgba(217, 160, 74, .25); border-top-color: var(--gold); border-radius: 50%; animation: rw-spin .8s steps(8) infinite; }
.rw-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.rw-btn { min-height: 46px; padding: 6px 18px 9px; font-size: 18px; border-radius: 6px; border: 2px solid var(--outline); }
.rw-btn.is-main { color: var(--ink); background: linear-gradient(#FFE7A6 0 48%, #F4C766 48% 100%); box-shadow: inset 0 2px 0 #FFF6D6, inset 0 -4px 0 #C98A38; }
.rw-btn.is-quiet { color: var(--cream); background: #3A2C36; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .3); border-color: #56424F; }
.rw-btn:hover { filter: brightness(1.08); }

/* ── Nút chính khi đang bận (tải game / đang vào) ── */
.rw-cta.is-busy { pointer-events: none; animation: none; font-size: 20px; filter: saturate(.75) brightness(.96); }
.rw-cta .rw-spin { width: 22px; height: 22px; margin: 0; flex: none; border-width: 3px; border-color: rgba(46, 30, 34, .25); border-top-color: var(--ink); }
.rw-name { color: var(--gold); }

/* ── Tiến độ tải game: vạch mảnh sát đáy + chữ ở chân trang ── */
.rw-load { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .4); pointer-events: none; transition: opacity .6s ease; }
.rw-load i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width .3s ease; }
.rw-load.is-done { opacity: 0; }

/* ── Chọn máy chủ (chỉ hiện khi có từ 2 máy chủ) ── */
.rw-srv { position: absolute; z-index: 2; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left));
          min-height: 44px; max-width: 46vw; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; font-size: 16px; color: var(--cream);
          background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.rw-srv[hidden] { display: none; }
.rw-srv span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rw-srv b { font-weight: normal; color: var(--gold); }
.rw-srv:hover { border-color: var(--gold); }
.rw-gate.has-srv .rw-pick { top: calc(max(14px, env(safe-area-inset-top)) + 52px); }
.rw-wallet.is-off { opacity: .55; }
.rw-wallet em.is-warn { color: var(--bad); }

/* ── Đặt tên nhân vật (ví chưa có nhân vật) ── */
.rw-form { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 2px; text-align: left; }
.rw-form label { font-size: 15px; color: var(--muted); }
.rw-input { width: 100%; min-height: 54px; padding: 8px 14px 10px; font-size: 22px; letter-spacing: .03em; color: var(--cream);
            background: #241B22; border: 2px solid #56424F; border-radius: 6px; box-shadow: inset 0 3px 0 rgba(0, 0, 0, .3); outline: none; }
.rw-input::placeholder { color: rgba(184, 163, 144, .55); }
.rw-input:focus { border-color: var(--gold-deep); }
.rw-input.is-bad { border-color: var(--bad); }
.rw-tip { margin: 0; font-size: 13px; color: var(--muted); }
.rw-err { margin: 0; min-height: 1.35em; font-size: 14px; color: var(--bad); }
.rw-form .rw-row { justify-content: flex-start; margin-top: 2px; }

@keyframes rw-fade { from { opacity: 0; } }
@keyframes rw-rise { from { transform: translateY(14px); opacity: 0; } }
@keyframes rw-spin { to { transform: rotate(360deg); } }

/* ── Màn ngang: chữ + nút đứng giữa, đè lên bản đồ; chỉ vùng sau chữ được làm mờ + tối nhẹ, hai bên đảo vẫn nét ── */
@media (min-aspect-ratio: 6/5) {
  .rw-shade { background: radial-gradient(ellipse 30% 46% at 50% 49%, rgb(var(--shade) / .44) 0, rgb(var(--shade) / .34) 55%, rgba(12, 16, 42, 0) 100%);
              -webkit-backdrop-filter: blur(2.5px); backdrop-filter: blur(2.5px);
              -webkit-mask-image: radial-gradient(ellipse 31% 48% at 50% 49%, #000 50%, transparent 100%);
              mask-image: radial-gradient(ellipse 31% 48% at 50% 49%, #000 50%, transparent 100%); }
  .rw-hero { justify-content: center; gap: clamp(16px, 4.4vh, 46px); padding: 50px 20px 86px; }
  .rw-logo { font-size: clamp(50px, min(12vw, 16vh), 150px); }
}
@media (min-aspect-ratio: 6/5) and (min-width: 1500px) and (min-height: 900px) { /* 1080p trở lên */
  .rw-tag { font-size: 34px; }
  .rw-sub { font-size: 21px; }
  .rw-cta { min-width: 380px; min-height: 78px; font-size: 31px; }
  .rw-cta svg { width: 32px; height: 32px; }
  .rw-hint { max-width: 560px; font-size: 18px; }
  .rw-account, .rw-link { font-size: 18px; }
  .rw-lang { min-width: 54px; height: 44px; font-size: 19px; }
  .rw-foot { font-size: 15px; }
}
@media (max-aspect-ratio: 6/5) {
  .rw-cta { width: min(100%, 330px); }
  .rw-toast { bottom: auto; top: 44%; } /* màn dọc: đáy đã kín nút + địa chỉ ví, thông báo hiện giữa đảo */
}
@media (max-aspect-ratio: 6/5) and (max-height: 700px) { /* điện thoại thấp */
  .rw-hero { padding-top: 40px; padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  .rw-safe { display: none; }
  .rw-hint { margin-top: 10px; }
}
@media (max-width: 520px) {
  .rw-pick .rw-lang { min-width: 30px; padding: 0 6px; }
  .rw-pick-name { min-width: 128px; padding: 0 2px; font-size: 13px; }
  .rw-modal { align-items: flex-end; padding: 0; }
  .rw-panel { width: 100%; max-height: 88%; border-radius: 12px 12px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .rw-hint { font-size: 14px; }
  /* Màn hẹp: tên nhân vật một dòng, địa chỉ ví nhỏ hơn ở dòng dưới — không để địa chỉ gãy giữa chừng. */
  .rw-account { max-width: 100%; }
  .rw-addr { display: flex; flex-direction: column; line-height: 1.2; }
  .rw-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rw-hex { font-size: 13px; color: var(--muted); }
  .rw-hex::before { content: none; }
  /* Đặt tên: bàn phím điện thoại che nửa dưới màn hình ⇒ khung nằm phía trên thay vì trượt lên từ đáy. */
  .rw-modal[data-view="name"] { align-items: flex-start; padding: max(56px, calc(env(safe-area-inset-top) + 16px)) 12px 0; }
  .rw-modal[data-view="name"] .rw-panel { border-radius: 8px; border-bottom: 2px solid var(--gold-deep); padding-bottom: 0; }
}
@media (max-height: 520px) { /* điện thoại xoay ngang */
  .rw-hero { padding-top: 10px; padding-bottom: 34px; gap: 14px; }
  .rw-sub, .rw-safe { display: none; }
  .rw-tag { margin-top: 8px; font-size: 17px; }
  .rw-cta { min-width: 0; min-height: 50px; font-size: 20px; padding: 6px 22px 10px; }
  .rw-hint { margin-top: 8px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .rw-cta.is-idle, .rw-modal, .rw-panel { animation: none; }
  .rw-scene, .rw-cta, .rw-toast { transition: none; }
}
