/* DRNO Mahjong */
:root {
  --bg1: #0b3a5c; --bg2: #0f6e74; --felt: rgba(255,255,255,0.05);
  --fg: #ffffff; --muted: rgba(255,255,255,0.78);
  --card: #fffdf7; --ink: #1b2a4a;
  --blue: #2f7cf6; --green: #19c37d; --gold: #ffc533;
  --tile: #fffaf0; --tile2: #f3e9cf; --side: #dccca3; --back: #1d7f8c;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
.theme-jade   { --bg1: #0c4433; --bg2: #2a8a5c; --back: #23785a; }
.theme-sunset { --bg1: #4b2546; --bg2: #b8643a; --back: #a4523a; }
.theme-night  { --bg1: #0f1220; --bg2: #26304e; --back: #3c4f8a; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 18px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--fg);
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255,255,255,0.12), transparent 60%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.screen.show { display: flex; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 58px; padding: 10px 20px; border: 0; border-radius: var(--radius);
  background: rgba(255,255,255,0.16); color: #fff; font-size: 20px; font-weight: 700;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.22); transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(0.97); }
.btn small { font-size: 15px; font-weight: 500; opacity: .9; margin-top: 2px; }
.btn.big { min-height: 76px; font-size: 24px; }
.btn.primary { background: linear-gradient(135deg, var(--blue), var(--green)); box-shadow: 0 6px 18px rgba(0,0,0,0.25); }
.btn.gold { background: linear-gradient(135deg, #ffb52e, #ff8a3d); color: #3a1d00; box-shadow: 0 6px 18px rgba(0,0,0,0.25); }
.btn.ghost { background: transparent; }
.btn.danger { background: #c63a3a; box-shadow: none; }
.btn:disabled { opacity: .45; }

/* ---------- home ---------- */
.home { margin: auto; width: min(460px, 100%); padding: 20px 22px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; overflow-y: auto; max-height: 100%; }
.home-logo { width: min(150px, 34vw); height: auto; border-radius: 50%; box-shadow: 0 10px 30px rgba(0,0,0,0.35); }
.title { margin: 10px 0 0; font: 800 40px/1.1 Georgia, 'Times New Roman', serif; letter-spacing: .5px; }
.title span { color: var(--gold); }
.tagline { margin: 0 0 14px; color: var(--muted); font-size: 19px; }
.home-btns { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-stats { margin: 12px 0 0; color: var(--muted); min-height: 1.4em; }
.legal { color: var(--muted); font-size: 16px; margin-top: 8px; }

/* ---------- topbar & lists ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.topbar h2 { flex: 1; margin: 0; text-align: center; font-size: 26px; }
.back { border: 0; background: rgba(255,255,255,0.16); border-radius: 14px; padding: 10px 16px; font-size: 20px; font-weight: 700; min-height: 52px; }
.spacer { width: 92px; }
.scroll { flex: 1; overflow-y: auto; padding: 4px 16px 24px; -webkit-overflow-scrolling: touch; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 12px; max-width: 760px; margin: 0 auto; }
.lvl { border: 0; border-radius: 16px; min-height: 92px; background: var(--tile); color: var(--ink);
  box-shadow: 4px 5px 0 var(--side), 6px 8px 0 var(--back); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.lvl b { font-size: 28px; }
.lvl small { font-size: 13px; color: #5b6475; white-space: nowrap; overflow: hidden; max-width: 90%; }
.lvl.done small { color: #d99a00; font-size: 17px; letter-spacing: 1px; }
.lvl.current { outline: 4px solid var(--gold); }
.lvl.locked { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.7); box-shadow: none; }
.lvl.locked small { color: rgba(255,255,255,0.7); }

/* ---------- daily ---------- */
.daily { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.streak { align-self: center; display: flex; align-items: baseline; gap: 8px; background: rgba(0,0,0,0.18); padding: 8px 20px; border-radius: 999px; }
.streak b { font-size: 30px; color: var(--gold); }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h3 { margin: 0; font-size: 24px; }
.cal-nav { width: 52px; height: 52px; border: 0; border-radius: 14px; background: rgba(255,255,255,0.16); font-size: 30px; line-height: 1; }
.cal-nav:disabled { opacity: .3; }
.cal-dow, .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.cal-dow span { color: var(--muted); font-size: 15px; font-weight: 700; }
.day { position: relative; aspect-ratio: 1; border: 0; border-radius: 12px; background: rgba(255,255,255,0.14); font-size: 19px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.day.done { background: linear-gradient(135deg, var(--blue), var(--green)); }
.day i { position: absolute; right: 4px; bottom: 1px; font-size: 13px; font-style: normal; }
.day.today { outline: 3px solid var(--gold); }
.day.future { opacity: .35; }
.cal-tip { text-align: center; color: var(--muted); margin: 4px 0; font-size: 16px; }

/* ---------- settings ---------- */
.settings { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 14px; background: rgba(0,0,0,0.18); border-radius: 16px; padding: 14px 16px; cursor: pointer; }
.opt span { display: flex; flex-direction: column; }
.opt small { color: var(--muted); font-size: 15px; }
.opt.col { flex-direction: column; align-items: stretch; cursor: default; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.sw { flex: none; width: 62px; height: 36px; border-radius: 999px; background: rgba(255,255,255,0.25); position: relative; transition: background .2s; }
.sw::after { content: ''; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform .2s; }
.opt input:checked + .sw { background: var(--green); }
.opt input:checked + .sw::after { transform: translateX(26px); }
.opt input:focus-visible + .sw { outline: 3px solid var(--gold); }
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.th { min-height: 56px; border: 0; border-radius: 12px; font-weight: 700; font-size: 16px; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25); }
.th.on { box-shadow: inset 0 0 0 4px var(--gold); }
.th-ocean { background: linear-gradient(135deg, #0b3a5c, #0f6e74); }
.th-jade { background: linear-gradient(135deg, #0c4433, #2a8a5c); }
.th-sunset { background: linear-gradient(135deg, #4b2546, #b8643a); }
.th-night { background: linear-gradient(135deg, #0f1220, #26304e); }
.version { text-align: center; color: var(--muted); font-size: 14px; margin: 0; }
.settings .legal { text-align: center; }

/* ---------- game ---------- */
.gbar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(0,0,0,0.2); }
.icon-btn { flex: none; width: 54px; height: 54px; border: 0; border-radius: 14px; background: rgba(255,255,255,0.16); font-size: 26px; }
.gtitle { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.gtitle b { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gtitle small { color: var(--muted); font-size: 15px; }
.gstats { display: flex; gap: 6px; }
.gstats div { display: flex; flex-direction: column; align-items: center; min-width: 58px; padding: 4px 6px; background: rgba(0,0,0,0.2); border-radius: 12px; line-height: 1.1; }
.gstats small { font-size: 13px; color: var(--muted); }
.gstats b { font-size: 21px; font-variant-numeric: tabular-nums; }

#board-wrap { flex: 1; position: relative; overflow: hidden; }
#board { position: absolute; inset: 0; z-index: 0; isolation: isolate; }
#board.shuffling .tile:not([hidden]) { animation: wobble .6s ease; }
@keyframes wobble { 0% { transform: none; } 40% { transform: scale(.86) rotate(-4deg); } 70% { transform: scale(1.04) rotate(2deg); } 100% { transform: none; } }

.tile {
  position: absolute; border-radius: calc(var(--tw) * 0.1);
  background: linear-gradient(145deg, var(--tile) 0%, var(--tile2) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(150,130,90,0.35),
    var(--e) var(--e) 0 0 var(--side),
    calc(var(--e) * 2) calc(var(--e) * 2) 0 0 var(--back),
    calc(var(--e) * 2 + 2px) calc(var(--e) * 2 + 3px) 6px 0 rgba(0,0,0,0.35);
  cursor: pointer; transition: transform .12s ease, background .12s;
}
.tile .face { position: absolute; inset: 4%; background: center / contain no-repeat; pointer-events: none; }
.tile::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: rgba(25,35,60,0.33); opacity: 0; transition: opacity .2s; pointer-events: none; }
.tile.blocked::after { opacity: 1; }
.tile::before { content: ''; position: absolute; inset: -3px; border-radius: inherit; border: 4px solid var(--gold); opacity: 0; pointer-events: none; z-index: 2; }
.tile.sel { background: linear-gradient(145deg, #fff6c2, #ffe27a); transform: translate(-2px, -4px); }
.tile.sel::before { opacity: 1; box-shadow: 0 0 14px var(--gold); }
.tile.hint::before { border-color: #3ee38f; box-shadow: 0 0 16px #3ee38f; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.tile.shake { animation: shake .35s ease; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
.tile.pop { animation: pop .38s ease forwards; pointer-events: none; }
@keyframes pop { 0% { transform: none; opacity: 1; } 40% { transform: scale(1.12) translateY(-6px); opacity: 1; } 100% { transform: scale(.4) translateY(-20px); opacity: 0; } }
.tile[hidden] { display: none; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 10px 12px calc(10px + var(--safe-b) * 0); background: rgba(0,0,0,0.2); }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 70px; border: 0; border-radius: 16px; background: rgba(255,255,255,0.16); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2); }
.tool .ico { font-size: 28px; line-height: 1; }
.tool b { font-size: 18px; }
.tool:active { transform: scale(.96); }
.tool:disabled { opacity: .4; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(5,10,20,0.6); }
.modal.show { display: flex; animation: fadein .2s ease; }
.card { width: min(440px, 100%); max-height: 92vh; overflow-y: auto; background: var(--card); color: var(--ink); border-radius: 24px; padding: 24px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.45); animation: rise .25s ease; }
@keyframes rise { from { transform: translateY(20px) scale(.97); } to { transform: none; } }
.card h2 { margin: 4px 0 10px; font: 800 28px/1.2 Georgia, serif; }
.m-logo { width: 72px; height: 72px; border-radius: 50%; }
.m-big { font-size: 20px; margin: 6px 0; }
.m-note { color: #4a5568; margin: 6px 0; font-size: 17px; }
.m-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.card .btn { color: var(--ink); background: #eef1f6; box-shadow: none; }
.card .btn.primary { color: #fff; background: linear-gradient(135deg, var(--blue), var(--green)); }
.card .btn.danger { color: #fff; background: #c63a3a; }
.card .btn.ghost { background: transparent; color: #3b4a66; }
.stars { font-size: 52px; letter-spacing: 6px; line-height: 1; color: #d9dde5; }
.stars span { display: inline-block; transition: transform .3s cubic-bezier(.3,1.8,.5,1), color .2s; transform: scale(.7); }
.stars .on { color: #ffb400; text-shadow: 0 2px 0 #d48a00; transform: scale(1.1); }
.help { text-align: left; padding-left: 22px; margin: 0; font-size: 18px; }
.help li { margin: 10px 0; }
.mini { display: inline-block; width: 30px; height: 40px; vertical-align: middle; margin-left: 4px; border-radius: 4px;
  background: center / 88% no-repeat, linear-gradient(145deg, var(--tile), var(--tile2)); box-shadow: 2px 2px 0 var(--side), 3px 3px 0 var(--back); }

/* ---------- toast & confetti ---------- */
#toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 60; max-width: min(92vw, 520px);
  background: rgba(15,22,40,0.94); color: #fff; padding: 14px 20px; border-radius: 16px; font-size: 18px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; transform: rotate(var(--r, 0deg)); }
@keyframes fall { to { top: 105%; transform: rotate(calc(var(--r, 0deg) + 720deg)) translateX(var(--drift, 40px)); } }

@media (max-width: 420px) {
  .gstats div { min-width: 50px; padding: 3px 4px; }
  .gstats b { font-size: 18px; }
  .gtitle b { font-size: 18px; }
  .icon-btn { width: 48px; height: 48px; }
}
@media (max-height: 560px) {
  .tool { min-height: 54px; flex-direction: row; gap: 8px; }
  .tool .ico { font-size: 22px; }
  .gbar { padding: 4px 10px; }
  .icon-btn { width: 46px; height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; transition: none !important; }
}

/* ===== v1.1 polish ===== */
/* splash */
.splash { margin: auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.splash-logo { width: min(180px, 42vw); border-radius: 50%; box-shadow: 0 12px 40px rgba(0,0,0,.4); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.04); } }
.splash-bar { width: 200px; height: 8px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; }
.splash-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--green)); animation: load .9s ease forwards; }
@keyframes load { to { width: 100%; } }

/* home decoration: drifting tiles in the background */
#s-home { overflow: hidden; }
.home-deco { display: none; position: absolute; inset: 0; pointer-events: none; opacity: .14;
  background-image:
    linear-gradient(145deg, #fff 0 0), linear-gradient(145deg, #fff 0 0), linear-gradient(145deg, #fff 0 0), linear-gradient(145deg, #fff 0 0);
  background-size: 70px 94px, 54px 72px, 62px 84px, 46px 62px;
  background-position: 8% 18%, 88% 12%, 92% 78%, 6% 84%;
  background-repeat: no-repeat; filter: blur(.3px); animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { background-position: 12% 24%, 84% 18%, 88% 72%, 10% 78%; } }
.home { position: relative; }
.home-logo { animation: breathe 4s ease-in-out infinite; }
.badge-prem { display: inline-block; margin-left: 6px; padding: 2px 10px; border-radius: 99px; background: linear-gradient(135deg, #ffd54a, #ff9f2e); color: #3a1d00; font-size: 14px; font-weight: 800; vertical-align: middle; }
.btn.prem { background: linear-gradient(135deg, #ffd54a, #ff9f2e); color: #3a1d00; box-shadow: 0 6px 18px rgba(0,0,0,.22); }
.card .btn.prem { color: #3a1d00; background: linear-gradient(135deg, #ffd54a, #ff9f2e); }

/* levels / daily / themes premium marks */
.lvl.premium { background: linear-gradient(145deg, rgba(255,213,74,.22), rgba(255,159,46,.18)); color: #ffe08a; box-shadow: inset 0 0 0 2px rgba(255,213,74,.45); }
.lvl.premium small { color: #ffe08a; }
.day.premium { background: rgba(255,213,74,.14); color: rgba(255,255,255,.7); }
.day.premium i { color: #ffd54a; }
.th.locked { opacity: .65; position: relative; }
.th.locked::after { content: '★'; position: absolute; top: 4px; right: 8px; color: #ffd54a; font-size: 14px; }
.prem-box { background: linear-gradient(135deg, rgba(255,213,74,.2), rgba(255,159,46,.12)); gap: 6px; }
.prem-box small { color: var(--muted); font-size: 15px; }

/* game bar extras */
.gstats div.low b { color: #ff7a7a; animation: pulse .9s ease-in-out infinite; }
.progress { height: 6px; background: rgba(0,0,0,.25); }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--green), var(--gold)); transition: width .4s ease; border-radius: 0 4px 4px 0; }
.icon-btn .ico { font-size: 18px; letter-spacing: -2px; }
.tool { position: relative; }
.tool .pill { position: absolute; top: 6px; right: 10px; min-width: 26px; padding: 1px 7px; border-radius: 99px; background: var(--gold); color: #3a1d00; font: 800 14px/1.4 system-ui, sans-serif; font-style: normal; }

/* tile life cycle */
.tile.deal { animation: dealIn .45s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes dealIn { from { opacity: 0; transform: translateY(-40px) scale(.6) rotate(-6deg); } to { opacity: 1; transform: none; } }
.tile.fly { animation: flyPair .5s cubic-bezier(.5,0,.6,1) forwards; pointer-events: none; }
@keyframes flyPair {
  0% { transform: none; opacity: 1; }
  50% { transform: translate(var(--fx), var(--fy)) scale(1.08); opacity: 1; }
  100% { transform: translate(var(--fx), var(--fy)) scale(.2) rotate(8deg); opacity: 0; } }
@media (hover: hover) {
  .tile.free:hover:not(.sel) { transform: translate(-1px, -3px); background: linear-gradient(145deg, #ffffff, #f7efd8); }
}

/* match burst */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.burst { position: absolute; width: 0; height: 0; }
.burst i { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; animation: spark .7s ease-out forwards; }
@keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.burst .pts { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); color: #fff; font: 900 26px/1 system-ui, sans-serif; text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 12px rgba(0,0,0,.35); white-space: nowrap; text-align: center; animation: rise2 1s ease-out forwards; }
.burst .pts small { display: block; font-size: 16px; color: var(--gold); }
@keyframes rise2 { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -160%) scale(1); } }

/* modal extras */
.card .row2 .btn { min-height: 52px; font-size: 17px; }
.result { display: flex; justify-content: center; gap: 12px; margin: 10px 0; }
.result div { display: flex; flex-direction: column; min-width: 110px; padding: 8px 12px; border-radius: 14px; background: #eef1f6; }
.result small { color: #5b6475; font-size: 15px; }
.result b { font-size: 28px; }
.perks { text-align: left; margin: 8px 0 14px; padding-left: 22px; font-size: 18px; }
.perks li { margin: 6px 0; }
.code-label { display: block; text-align: left; font-weight: 700; margin-bottom: 6px; }
.code-in { width: 100%; min-height: 56px; padding: 10px 14px; border-radius: 14px; border: 2px solid #c9d2e0; font: 700 18px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; text-transform: uppercase; color: var(--ink); background: #fff; }
.code-in:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,124,246,.25); }
.code-err { color: #c63a3a; min-height: 1.2em; margin: 6px 0 0; font-size: 16px; }
.m-note.small { font-size: 15px; }
