:root {
  --shell: #c3b1e1; --shellD: #a58fcf; --ink: #3b2a35; --pink: #ff6f91; --pinkD: #c94a6d; --cream: #fff8e7;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--shell); color: var(--ink);
  touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: none; }

/* ------------------------------------------------ console layout (portrait) */
#app {
  position: fixed; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr auto;
  grid-template-areas: "screen screen" "padL padR" "padM padM";
}
#screen {
  grid-area: screen; margin: 10px 10px 0; padding: 10px; height: min(56dvh, 100vw);
  background: #2b2233; border-radius: 14px 14px 30px 14px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .3), 0 4px 0 var(--shellD);
}
#view { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 4px; background: #1d1724; }
#game { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

.pad { position: relative; display: flex; align-items: center; justify-content: center; min-height: 190px; }
#padL { grid-area: padL; }
#padR { grid-area: padR; }
#padM { grid-area: padM; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 12px; }
#keys { display: none; }

.shoulder {
  position: absolute; top: 12px; width: 78px; height: 34px; border: none; border-radius: 10px 10px 6px 6px;
  background: #8a7aa8; color: #fff; font-weight: 800; font-size: 15px; box-shadow: 0 3px 0 #6c5d8a;
}
#padL .shoulder { left: 14px; }
#padR .shoulder { right: 14px; }
.shoulder.on { transform: translateY(2px); box-shadow: 0 1px 0 #6c5d8a; }

#dpad { position: relative; width: 156px; height: 156px; margin-top: 30px; touch-action: none; }
#dpad .arm, #dpad .hub { position: absolute; background: var(--ink); }
#dpad .arm.up { left: 52px; top: 0; width: 52px; height: 56px; border-radius: 9px 9px 0 0; }
#dpad .arm.down { left: 52px; bottom: 0; width: 52px; height: 56px; border-radius: 0 0 9px 9px; }
#dpad .arm.left { top: 52px; left: 0; width: 56px; height: 52px; border-radius: 9px 0 0 9px; }
#dpad .arm.right { top: 52px; right: 0; width: 56px; height: 52px; border-radius: 0 9px 9px 0; }
#dpad .hub { left: 52px; top: 52px; width: 52px; height: 52px; }
#dpad .hub::after { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: #4a3a48; }
#dpad .arm::after { content: ""; position: absolute; left: 50%; top: 50%; border: 8px solid transparent; transform: translate(-50%, -50%); }
#dpad .arm.up::after { border-bottom-color: #6b5a70; margin-top: -4px; }
#dpad .arm.down::after { border-top-color: #6b5a70; margin-top: 4px; }
#dpad .arm.left::after { border-right-color: #6b5a70; margin-left: -4px; }
#dpad .arm.right::after { border-left-color: #6b5a70; margin-left: 4px; }
#dpad .arm.on { background: #5e4b5c; }
#dpad { filter: drop-shadow(0 4px 0 rgba(59, 42, 53, .35)); }

#stick { width: 156px; height: 156px; margin-top: 30px; border-radius: 50%; background: rgba(59, 42, 53, .18); box-shadow: inset 0 4px 10px rgba(59, 42, 53, .3); display: flex; align-items: center; justify-content: center; touch-action: none; }
#stick .knob { width: 66px; height: 66px; border-radius: 50%; background: var(--ink); box-shadow: 0 4px 0 rgba(0, 0, 0, .3); pointer-events: none; }

#ab { position: relative; width: 164px; height: 150px; margin-top: 30px; }
.btn {
  position: absolute; width: 70px; height: 70px; border-radius: 50%; border: none;
  background: var(--pink); color: #fff; font-weight: 900; font-size: 24px; box-shadow: 0 5px 0 var(--pinkD);
}
.btn.a { right: 4px; top: 6px; }
.btn.b { left: 4px; bottom: 6px; }
.btn.on { transform: translateY(4px); box-shadow: 0 1px 0 var(--pinkD); }

.pill { width: 88px; height: 28px; border: none; border-radius: 14px; background: #8a7aa8; color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 2px; box-shadow: 0 3px 0 #6c5d8a; }
.pill.on { transform: translateY(2px); box-shadow: 0 1px 0 #6c5d8a; }
.brand { font-size: 11px; letter-spacing: 4px; color: #8a73b8; font-weight: 900; }

/* ------------------------------------------------ landscape phones */
@media (orientation: landscape) and (max-height: 560px) {
  #app { grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr auto; grid-template-areas: "padL screen padR" "padL padM padR"; }
  #screen { height: auto; margin: 8px 0 0; padding: 6px; width: min(calc(100vw - 340px - env(safe-area-inset-left) - env(safe-area-inset-right)), calc((100dvh - 56px) * 1.5)); }
  #padM { flex-direction: row; padding-bottom: 6px; padding-top: 6px; }
  .brand { display: none; }
  .pad { min-height: 0; }
  #dpad, #stick, #ab { margin-top: 36px; transform: scale(.92); }
  .shoulder { top: 8px; }
}

/* ------------------------------------------------ desktop: keyboard, no pad (class set in index.html) */
html.desk #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; grid-template-areas: "screen" "padM" "keys"; }
html.desk #padL, html.desk #padR { display: none; }
html.desk #screen { height: auto; margin: 16px auto 0; width: min(96vw, calc((100dvh - 120px) * 1.5)); }
html.desk #padM { padding: 10px 0 4px; flex-direction: row; justify-content: center; gap: 14px; }
html.desk #keys { display: block; grid-area: keys; text-align: center; font-size: 13px; padding: 0 10px 12px; color: #5d4a80; }

/* ------------------------------------------------ menus */
#menu { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 8px; background: rgba(29, 23, 36, .45); }
.win { width: min(100%, 460px); max-height: 100%; display: flex; flex-direction: column; background: var(--cream); border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; box-shadow: 0 4px 0 rgba(0, 0, 0, .35); }
.title { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 6px 12px; background: #ffd6e3; border-bottom: 3px solid var(--ink); font-weight: 900; font-size: 16px; }
.title button { border: none; background: none; font-size: 18px; width: 36px; height: 30px; }
.tabs { display: flex; gap: 4px; padding: 6px 8px 0; background: #fff1d6; overflow-x: auto; }
.tab { padding: 5px 10px; border-radius: 8px 8px 0 0; background: #f2dfba; font-weight: 800; font-size: 13px; white-space: nowrap; }
.tab.on { background: var(--cream); box-shadow: inset 0 3px 0 var(--pink); }
.head { padding: 6px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; border-bottom: 2px dashed #e8d5b0; }
.gold { font-weight: 900; color: #a87a00; font-size: 14px; }
.say { color: #6b5a75; }
.list { flex: 1; overflow-y: auto; padding: 4px; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; min-height: 46px; border-radius: 8px; border: 2px solid transparent; }
.row img { width: 32px; height: 32px; image-rendering: pixelated; flex: none; }
.row .emo { width: 32px; text-align: center; font-size: 21px; flex: none; }
.row .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row b { font-size: 14.5px; }
.row small { font-size: 11.5px; color: #7a6a80; }
.row .right { font-weight: 900; font-size: 13.5px; color: #a87a00; white-space: nowrap; }
.row.cur { background: #ffe9a8; border-color: var(--ink); }
.row.mark { background: #dcf5cc; }
.row.cur.mark { background: #c6efae; }
.row.dis { opacity: .45; }
.altbtn { background: var(--pink); color: #fff; font-weight: 900; font-size: 12.5px; border-radius: 8px; padding: 7px 9px; }
.bar { display: block; height: 6px; margin-top: 3px; background: #e8d5b0; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #ff9f43; transition: width .5s linear; }
.foot { padding: 4px 10px; font-size: 11px; text-align: center; color: #8a7a90; background: #fff1d6; }
.empty { padding: 22px 12px; text-align: center; color: #8a7a90; }

/* ------------------------------------------------ toasts, cards, status */
#toasts { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); width: 92%; z-index: 6; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.toast { background: rgba(59, 42, 53, .93); color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 700; text-align: center; animation: pop .18s ease-out; transition: opacity .4s, transform .4s; }
.toast.err { background: rgba(176, 52, 86, .95); }
.toast.coin { background: rgba(150, 104, 8, .95); }
.toast.level { background: rgba(62, 140, 74, .96); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
#daycard { position: absolute; inset: 0; z-index: 7; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#daycard > div { background: var(--cream); border: 3px solid var(--ink); border-radius: 12px; padding: 12px 26px; text-align: center; box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
#daycard h2 { margin: 0 0 4px; font-size: 26px; }
#daycard p { margin: 2px 0; font-size: 14px; }
#daycard .pay b { color: #a87a00; }
#daycard.fade { animation: card 3s forwards; }
@keyframes card { 0% { opacity: 0; transform: scale(.9); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#status { position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%); z-index: 8; background: var(--ink); color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 700; }

/* ------------------------------------------------ join screen */
#join { position: fixed; inset: 0; z-index: 20; overflow-y: auto; touch-action: pan-y; display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 12px); background: linear-gradient(#ffd6e3, var(--shell)); }
#joinform { width: min(360px, 100%); margin: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 6px 0 rgba(59, 42, 53, .25); }
#joinform h1 { margin: 0; font-size: 28px; }
#joinform .tag { margin: 0 0 4px; color: #7a6a80; }
#preview { width: 88px; height: 96px; padding: 10px 12px; image-rendering: pixelated; background: #bfe6a0; border: 3px solid var(--ink); border-radius: 12px; }
#joinform label { width: 100%; display: flex; flex-direction: column; gap: 4px; font-weight: 800; }
#joinform input { font: inherit; font-size: 18px; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; -webkit-user-select: text; user-select: text; touch-action: manipulation; }
.lbl { align-self: flex-start; font-weight: 800; margin-top: 2px; }
.sws { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 7px; }
.sw { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid var(--ink); touch-action: manipulation; }
.sw.on { outline: 3px solid var(--pink); outline-offset: 2px; }
#play { width: 100%; margin-top: 10px; padding: 12px; font-size: 20px; font-weight: 900; color: #fff; background: var(--pink); border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 4px 0 var(--ink); touch-action: manipulation; }
#play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tip { margin: 0; font-size: 12px; color: #7a6a80; }
