/* ============================================================
   ลิงชิงบอล — The Monkey Game : Stylesheet
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg1: #1a936f;
  --bg2: #114b5f;
  --accent: #ffd93b;
  --accent2: #ff8c42;
  --card: rgba(255, 255, 255, 0.94);
  --ink: #21354a;
  --ink-soft: #5c7186;
  --radius: 22px;
}

html, body {
  height: 100%;
  font-family: 'Prompt', 'Kanit', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  overflow-x: hidden;
}

body {
  background: linear-gradient(150deg, var(--bg1) 0%, var(--bg2) 100%);
}

.hidden { display: none !important; }

.screen { min-height: 100vh; width: 100%; }

/* ============================ HOME ============================ */

#home-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 18px 20px;
}

.home-bg-deco {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(circle at 12% 20%, rgba(255,217,59,.14) 0 140px, transparent 141px),
    radial-gradient(circle at 88% 15%, rgba(255,140,66,.16) 0 110px, transparent 111px),
    radial-gradient(circle at 85% 80%, rgba(255,255,255,.07) 0 170px, transparent 171px),
    radial-gradient(circle at 8% 85%, rgba(255,255,255,.06) 0 130px, transparent 131px);
}

/* ปุ่มเต็มหน้าจอมุมขวาบนของหน้า Home (แสดงเฉพาะบนคอม) */
.fs-btn {
  position: absolute; top: 20px; right: 22px; z-index: 3;
  font-family: 'Kanit', sans-serif;
  font-size: 14px; font-weight: 600;
  color: #fff;
  background: rgba(255,255,255,.16);
  border: 2px solid rgba(255,255,255,.35);
  border-radius: 14px;
  padding: 9px 16px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all .15s;
}
.fs-btn:hover { background: rgba(255,255,255,.28); transform: translateY(-2px); }

.home-header { position: relative; z-index: 1; text-align: center; margin-bottom: 24px; }

.logo-row { display: flex; align-items: center; justify-content: center; gap: 16px; }

.logo-emoji {
  font-size: 56px;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.3));
  animation: bob 2.6s ease-in-out infinite;
}
.logo-row .logo-emoji:last-child { animation-delay: 1.3s; }

@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }

.logo-text h1 {
  font-family: 'Kanit', sans-serif;
  font-size: clamp(44px, 7vw, 72px);
  font-weight: 800;
  color: #fff;
  line-height: 1.05;
  text-shadow: 0 4px 0 rgba(0,0,0,.18), 0 10px 26px rgba(0,0,0,.35);
  letter-spacing: 1px;
}

.logo-sub {
  font-family: 'Kanit', sans-serif;
  font-weight: 600;
  letter-spacing: 8px;
  color: var(--accent);
  font-size: clamp(12px, 1.6vw, 16px);
  margin-top: 2px;
}

.tagline { color: rgba(255,255,255,.85); margin-top: 10px; font-size: 16px; }

.home-grid {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 330px minmax(360px, 520px) 300px;
  gap: 20px;
  align-items: stretch;   /* ทุกการ์ดสูงเท่ากัน ขอบล่างจบตรงกันพอดี */
  justify-content: center;
  width: 100%;
  max-width: 1240px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 18px 40px rgba(8, 34, 48, .35);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
}

.card h2 {
  font-family: 'Kanit', sans-serif;
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.card h2.mt { margin-top: 22px; }
.card-ic { font-size: 22px; }

/* --- แท็บ คน / ลิง --- */
.tab-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  font-family: 'Kanit', sans-serif;
  font-size: 16px; font-weight: 600;
  padding: 10px 8px;
  border-radius: 14px;
  border: 3px solid #dde7f0;
  background: #f2f6fa;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.tab-btn:hover { transform: translateY(-1px); border-color: #b9cfe2; }
.tab-btn.selected {
  background: linear-gradient(160deg, #fff8e0, #ffefc2);
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(255, 200, 40, .3);
}

/* --- พรีวิวตัวละคร --- */
.preview-wrap {
  display: flex; justify-content: center; align-items: center;
  background: linear-gradient(160deg, #56b8ff, #3d8bfd);
  border-radius: 18px;
  margin-bottom: 14px;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.35);
  flex: 1;                /* ยืดเต็มพื้นที่ว่างที่เหลือ ทำให้การ์ดจบพอดีกับใบอื่น */
  min-height: 180px;
}
#preview-canvas { width: 100%; max-width: 215px; height: auto; aspect-ratio: 1; }

.field-label {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

#player-name, #modal-name {
  width: 100%;
  font-family: inherit;
  font-size: 18px; font-weight: 600;
  padding: 11px 14px;
  border: 2.5px solid #d7e2ec;
  border-radius: 14px;
  outline: none;
  transition: border-color .15s;
  color: var(--ink);
}
#player-name:focus, #modal-name:focus { border-color: var(--accent2); }

/* --- กลุ่มสี: ทั้งสองแท็บมี 3 กลุ่ม กลุ่มละ 8 สี = ความสูงเท่ากันเป๊ะ --- */
.custom-panel { display: flex; flex-direction: column; gap: 12px; }

.custom-group { display: flex; flex-direction: column; }

.swatch-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,.12);
  cursor: pointer;
  padding: 0;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--accent);
  transform: scale(1.12);
}

/* --- เริ่มเล่น (3 ตัวเลือกเวลา: 1 / 3 / 5 นาที) --- */
.time-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.start-btn {
  font-family: 'Kanit', sans-serif;
  border: none;
  border-radius: 18px;
  padding: 16px 6px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .1s, box-shadow .1s;
}
.start-btn.t1 {
  background: linear-gradient(160deg, #ffd93b, #ff9f1c);
  color: #4a2c00;
  box-shadow: 0 8px 0 #d17f00, 0 16px 28px rgba(0,0,0,.25);
}
.start-btn.t3 {
  background: linear-gradient(160deg, #6ee7b7, #16a37c);
  color: #05372a;
  box-shadow: 0 8px 0 #0c7a5c, 0 16px 28px rgba(0,0,0,.25);
}
.start-btn.t5 {
  background: linear-gradient(160deg, #7cc0ff, #2f6fe0);
  color: #0b2b55;
  box-shadow: 0 8px 0 #1c4fb0, 0 16px 28px rgba(0,0,0,.25);
}
.start-btn:hover { transform: translateY(-3px); }
.start-btn:active { transform: translateY(3px); }
.start-btn.t1:active { box-shadow: 0 3px 0 #d17f00; }
.start-btn.t3:active { box-shadow: 0 3px 0 #0c7a5c; }
.start-btn.t5:active { box-shadow: 0 3px 0 #1c4fb0; }
.start-big { font-size: 24px; font-weight: 800; }
.start-small { font-size: 13px; font-weight: 600; opacity: .85; }

.random-note {
  margin-top: 14px;
  background: linear-gradient(90deg, #fff3c8, #ffe9a8);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--ink);
  text-align: center;
}

.howto {
  margin-top: 22px;
  background: #f4f8fb;
  border-radius: 16px;
  padding: 16px 18px;
  flex: 1;   /* ยืดเต็มพื้นที่ว่าง ขอบล่างจึงตรงกับการ์ดอื่น */
}
.howto h3 { font-family: 'Kanit', sans-serif; font-size: 15px; margin-bottom: 6px; }
.howto h3:not(:first-child) { margin-top: 12px; }
.howto ul { list-style: none; }
.howto li {
  font-size: 13.5px; color: var(--ink-soft);
  padding-left: 18px; position: relative;
  margin-bottom: 4px; line-height: 1.5;
}
.howto li::before { content: '•'; color: var(--accent2); position: absolute; left: 4px; font-weight: 700; }
.howto b { color: var(--ink); }

/* สลับคำอธิบายการบังคับตามอุปกรณ์ (JS ใส่คลาสที่ body) */
.ctrl-mobile { display: none; }
body.is-mobile .ctrl-desktop { display: none; }
body.is-mobile .ctrl-mobile { display: block; }

/* --- สถิติ --- */
.stats-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  background: #f2f6fa;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
}
.stat-row b { font-family: 'Kanit', sans-serif; font-size: 17px; }
.stat-row.hl { background: linear-gradient(90deg, #fff3c8, #ffe9a8); }

.ghost-btn {
  font-family: inherit;
  background: transparent;
  border: 2px solid #cfdae4;
  color: var(--ink-soft);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.ghost-btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.ghost-btn.full { width: 100%; margin-top: 14px; }

.sound-row { display: flex; gap: 8px; margin-top: 12px; }
.sound-row .ghost-btn { flex: 1; }

/* ดันปุ่มล่างของการ์ดสถิติไปชิดขอบล่าง เวลาการ์ดถูกยืด */
.stats-card #reset-stats { margin-top: auto; }

.home-footer {
  position: relative; z-index: 1;
  margin-top: 26px;
  color: rgba(255,255,255,.65);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 1120px) {
  .home-grid { grid-template-columns: minmax(300px, 480px); }
}

/* ============================ MODAL ใส่ชื่อ ============================ */

.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 26, 38, .62);
  backdrop-filter: blur(4px);
  animation: fade-in .18s ease-out;
  padding: 20px;
}
@keyframes fade-in { from { opacity: 0 } }

.name-card { max-width: 400px; animation: card-pop .3s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes card-pop { from { transform: scale(.8); opacity: 0; } }

.name-desc { color: var(--ink-soft); font-size: 14.5px; margin-top: -6px; line-height: 1.5; }

.name-error {
  color: #e5484d;
  font-size: 13px; font-weight: 600;
  margin-top: -4px;
  visibility: hidden;
}
.name-error.show { visibility: visible; }

/* ============================ IN-GAME ============================ */

#game-screen {
  position: fixed; inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

.hud-top {
  position: absolute; top: 14px; left: 0; right: 0;
  display: flex; justify-content: center; align-items: flex-start;
  gap: 18px;
  padding: 0 14px;
}

.hud-pill {
  background: rgba(12, 40, 56, .78);
  color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px; font-weight: 500;
  box-shadow: 0 6px 16px rgba(0,0,0,.3);
  white-space: nowrap;
  margin-top: 8px;
}
.hud-pill b { font-family: 'Kanit', sans-serif; font-size: 20px; color: var(--accent); margin-left: 4px; }

.hud-center { display: flex; flex-direction: column; align-items: center; gap: 5px; }

.hud-timer {
  font-family: 'Kanit', sans-serif;
  font-size: 42px; font-weight: 800;
  color: #fff;
  background: rgba(12, 40, 56, .78);
  border-radius: 20px;
  padding: 2px 26px;
  box-shadow: 0 6px 16px rgba(0,0,0,.3);
  letter-spacing: 2px;
}
.hud-timer.warn { color: #ff6b6b; animation: pulse .8s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.hud-monkey {
  background: rgba(255, 217, 59, .95);
  color: #4a2c00;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
  padding: 4px 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,.25);
}

.hud-right {
  position: absolute; top: 14px; right: 14px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: auto;
}

.hud-btn {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: none;
  font-size: 20px;
  background: rgba(12, 40, 56, .78);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  transition: transform .1s, background .15s;
}
.hud-btn:hover { transform: scale(1.08); background: rgba(20, 60, 82, .9); }
.hud-btn.off { opacity: .45; }

.hud-role {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(12, 40, 56, .78);
  color: #fff;
  border-radius: 999px;
  padding: 8px 22px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(0,0,0,.3);
  white-space: nowrap;
}

.hud-hint {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.92);
  font-size: 13.5px;
  background: rgba(0,0,0,.35);
  border-radius: 10px;
  padding: 5px 14px;
  transition: opacity 1s;
  white-space: nowrap;
}
.hud-hint.fade { opacity: 0; }

/* ป้ายเปลี่ยนลิง */
.overlay-banner {
  position: absolute; top: 26%; left: 50%; transform: translate(-50%, -50%);
  z-index: 8;
  font-family: 'Kanit', sans-serif;
  font-size: clamp(24px, 4.5vw, 44px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, #ff8c42, #e5484d);
  padding: 14px 40px;
  border-radius: 999px;
  box-shadow: 0 14px 40px rgba(0,0,0,.45);
  animation: banner-pop .45s cubic-bezier(.2, 2.2, .4, 1);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}
@keyframes banner-pop { from { transform: translate(-50%,-50%) scale(.3); opacity: 0; } }

/* overlay ทั่วไป */
.overlay {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 26, 38, .55);
  backdrop-filter: blur(3px);
}

#countdown-overlay { background: rgba(8, 26, 38, .25); }
#countdown-num {
  font-family: 'Kanit', sans-serif;
  font-size: 160px; font-weight: 800;
  color: #fff;
  text-shadow: 0 8px 0 rgba(0,0,0,.2), 0 20px 50px rgba(0,0,0,.5);
  animation: count-pop .9s ease-out infinite;
}
@keyframes count-pop { from { transform: scale(1.55); opacity: .2; } 40% { transform: scale(1); opacity: 1; } }

.overlay-card {
  background: var(--card);
  border-radius: 26px;
  padding: 34px 40px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 14px;
  min-width: 300px;
  max-width: 92vw;
  max-height: 92vh;
  overflow-y: auto;
}
.overlay-card h2 { font-family: 'Kanit', sans-serif; font-size: 34px; font-weight: 800; }

.big-btn {
  font-family: 'Kanit', sans-serif;
  font-size: 20px; font-weight: 700;
  border: none;
  border-radius: 16px;
  padding: 14px 20px;
  cursor: pointer;
  background: linear-gradient(160deg, #ffd93b, #ff9f1c);
  color: #4a2c00;
  box-shadow: 0 6px 0 #d17f00;
  transition: transform .1s;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #d17f00; }

.end-card #end-reason { color: var(--ink-soft); font-size: 15px; margin-top: -6px; }

.end-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  text-align: left;
}
.end-stat {
  background: #f2f6fa;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink-soft);
}
.end-stat b { display: block; font-family: 'Kanit', sans-serif; font-size: 22px; color: var(--ink); }

.end-btn-row { display: flex; gap: 10px; justify-content: center; }

.lb-title {
  font-family: 'Kanit', sans-serif;
  font-size: 16px; font-weight: 600;
  text-align: left;
  margin-top: 2px;
}

.lb-list { display: flex; flex-direction: column; gap: 6px; text-align: left; }

.lb-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 10px;
  background: #f2f6fa;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13.5px;
}
.lb-row.me { background: linear-gradient(90deg, #fff3c8, #ffe9a8); }
.lb-row.top1 { background: linear-gradient(90deg, #ffe9a8, #ffd257); }

.lb-rank {
  font-family: 'Kanit', sans-serif;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
}
.lb-row.top1 .lb-rank, .lb-row.top2 .lb-rank, .lb-row.top3 .lb-rank { color: var(--ink); }

.lb-name { color: var(--ink); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lb-score { font-family: 'Kanit', sans-serif; font-weight: 700; color: var(--ink); }
.lb-score::after { content: ' แต้ม'; font-family: 'Prompt', sans-serif; font-weight: 500; font-size: 11px; color: var(--ink-soft); }

/* ============================ ปุ่มสัมผัสมือถือ ============================ */

.touch-ui { z-index: 6; }

#touch-joystick {
  position: absolute; left: max(26px, env(safe-area-inset-left)); bottom: 26px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  border: 2.5px solid rgba(255,255,255,.4);
  touch-action: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,.78);
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 10px rgba(0,0,0,.3);
  pointer-events: none;
}

#touch-buttons {
  position: absolute; right: max(26px, env(safe-area-inset-right)); bottom: 26px;
  display: flex; align-items: flex-end; gap: 14px;
}

.touch-btn {
  border: none;
  border-radius: 50%;
  font-family: 'Kanit', sans-serif;
  font-weight: 700;
  color: #4a2c00;
  touch-action: none;
  transition: transform .08s;
}
.touch-btn.main {
  width: 104px; height: 104px;
  font-size: 18px;
  background: linear-gradient(160deg, #ffd93b, #ff9f1c);
  box-shadow: 0 6px 0 #d17f00, 0 12px 26px rgba(0,0,0,.4);
}
.touch-btn.lob {
  width: 78px; height: 78px;
  font-size: 16px;
  color: #05372a;
  background: linear-gradient(160deg, #6ee7b7, #16a37c);
  box-shadow: 0 6px 0 #0c7a5c, 0 12px 26px rgba(0,0,0,.4);
}
.touch-btn:active { transform: translateY(4px); }
.touch-btn.main:active { box-shadow: 0 2px 0 #d17f00; }
.touch-btn.lob:active { box-shadow: 0 2px 0 #0c7a5c; }

/* ============================ ป้ายหมุนจอ ============================ */

#rotate-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--bg1), var(--bg2));
  text-align: center;
  padding: 30px;
}
.rotate-inner { color: #fff; max-width: 320px; }
.rotate-icon {
  font-size: 72px;
  display: inline-block;
  animation: rotate-hint 1.8s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%, 40% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(-90deg); }
}
.rotate-inner h2 { font-family: 'Kanit', sans-serif; font-size: 26px; margin: 14px 0 8px; }
.rotate-inner p { font-size: 15px; color: rgba(255,255,255,.8); line-height: 1.6; }

/* ============================ จอเล็ก / แนวนอนมือถือ ============================ */

@media (max-width: 700px) {
  #home-screen { padding: 20px 14px 16px; }
  .home-grid { grid-template-columns: 1fr; max-width: 460px; }
  .logo-emoji { font-size: 42px; }
  .fs-btn { display: none !important; }
}

@media (max-height: 500px) {
  .hud-pill { font-size: 12px; padding: 6px 12px; margin-top: 4px; }
  .hud-pill b { font-size: 15px; }
  .hud-timer { font-size: 28px; padding: 0 18px; }
  .hud-monkey { font-size: 11px; padding: 3px 12px; }
  .hud-role { font-size: 12px; bottom: 8px; padding: 5px 16px; }
  .hud-hint { display: none; }
  .hud-btn { width: 38px; height: 38px; font-size: 16px; border-radius: 11px; }
  #touch-joystick { width: 112px; height: 112px; bottom: 14px; }
  #joy-knob { width: 48px; height: 48px; }
  #touch-buttons { bottom: 14px; gap: 10px; }
  .touch-btn.main { width: 82px; height: 82px; font-size: 15px; }
  .touch-btn.lob { width: 62px; height: 62px; font-size: 13px; }
  #countdown-num { font-size: 92px; }
  .overlay-card { padding: 20px 26px; gap: 10px; }
  .overlay-card h2 { font-size: 24px; }
  .end-stat { padding: 7px 10px; font-size: 11px; }
  .end-stat b { font-size: 17px; }
  .big-btn { font-size: 16px; padding: 10px 16px; }
  .lb-title { font-size: 13px; }
  .lb-list { gap: 4px; }
  .lb-row { padding: 5px 10px; font-size: 11.5px; grid-template-columns: 20px 1fr auto; gap: 7px; }
  .lb-score::after { display: none; }
}

/* ============================ Home แนวนอนบนมือถือ ============================
   จอเตี้ยแนวนอน (มือถือ): ย่อทุกอย่างและเรียง 3 การ์ดข้างกันเหมือนเดสก์ท็อป
   ต้องอยู่ท้ายไฟล์เพื่อชนะกฎ 1 คอลัมน์ของ max-width: 700px */

@media (orientation: landscape) and (max-height: 520px) {
  body.is-mobile #home-screen { padding: 10px 12px 12px; }
  body.is-mobile .home-header { margin-bottom: 10px; }
  body.is-mobile .logo-row { gap: 10px; }
  body.is-mobile .logo-emoji { font-size: 28px; }
  body.is-mobile .logo-text h1 { font-size: 30px; }
  body.is-mobile .logo-sub { letter-spacing: 4px; font-size: 10px; }
  body.is-mobile .tagline { display: none; }
  body.is-mobile .home-grid {
    grid-template-columns: minmax(190px, 240px) minmax(230px, 340px) minmax(190px, 240px);
    gap: 10px;
    max-width: none;
  }
  body.is-mobile .card { padding: 12px; border-radius: 16px; }
  body.is-mobile .card h2 { font-size: 13.5px; margin-bottom: 8px; gap: 5px; }
  body.is-mobile .card h2.mt { margin-top: 12px; }
  body.is-mobile .card-ic { font-size: 15px; }
  body.is-mobile .tab-btn { font-size: 12.5px; padding: 6px; border-radius: 10px; border-width: 2px; }
  body.is-mobile .tab-row { gap: 6px; margin-bottom: 8px; }
  body.is-mobile .preview-wrap { min-height: 90px; margin-bottom: 8px; border-radius: 12px; }
  body.is-mobile #preview-canvas { max-width: 118px; }
  body.is-mobile #player-name { font-size: 14px; padding: 8px 10px; border-radius: 10px; }
  body.is-mobile .field-label { font-size: 10.5px; margin-bottom: 4px; }
  body.is-mobile .custom-panel { gap: 7px; }
  body.is-mobile .swatch-row { gap: 4px; }
  body.is-mobile .swatch { border-width: 2px; }
  body.is-mobile .time-row { gap: 7px; }
  body.is-mobile .start-btn { padding: 9px 4px; border-radius: 12px; }
  body.is-mobile .start-big { font-size: 16px; }
  body.is-mobile .start-small { font-size: 9.5px; }
  body.is-mobile .random-note { font-size: 10.5px; padding: 6px 10px; margin-top: 8px; border-radius: 9px; }
  body.is-mobile .howto { padding: 10px 12px; margin-top: 10px; border-radius: 12px; }
  body.is-mobile .howto h3 { font-size: 11.5px; }
  body.is-mobile .howto li { font-size: 10px; margin-bottom: 3px; padding-left: 13px; }
  body.is-mobile .stat-row { padding: 6px 10px; font-size: 10.5px; border-radius: 9px; }
  body.is-mobile .stat-row b { font-size: 12.5px; }
  body.is-mobile .stats-list { gap: 5px; margin-bottom: 8px; }
  body.is-mobile .ghost-btn { padding: 6px 8px; font-size: 10.5px; border-radius: 9px; }
  body.is-mobile .ghost-btn.full { margin-top: 8px; }
  body.is-mobile .sound-row { margin-top: 8px; gap: 5px; }
  body.is-mobile .home-footer { margin-top: 10px; font-size: 9.5px; }
  body.is-mobile .name-card { max-width: 340px; padding: 20px 24px; gap: 10px; }
  body.is-mobile .name-card h2 { font-size: 22px; }
}
