:root {
  --mt-bg: #1b1410;
  --mt-panel: #fffaf2;
  --mt-ink: #202331;
  --mt-muted: #6f6a7d;
  --mt-gold: #f5c518;
  --mt-gold-dark: #c99a00;
  --mt-red: #e5484d;
  --mt-green: #18b86a;
  --mt-line: #e8dfd1;
}
* { box-sizing: border-box; }
body.mt-page {
  margin: 0;
  min-height: 100vh;
  font-family: Pretendard, "Noto Sans KR", system-ui, sans-serif;
  color: #fff;
  background: radial-gradient(circle at 50% -10%, #5a3a22 0, var(--mt-bg) 60%);
}
button, input { font: inherit; }
.hidden { display: none !important; }

/* 상단 메뉴 */
.mt-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 18px; background: rgba(0, 0, 0, .35);
}
.mt-toolbar a { color: #ffe9a8; font-weight: 800; text-decoration: none; }
.mt-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mt-toolbar button {
  border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer;
  background: rgba(255, 255, 255, .12); color: #fff; font-weight: 700;
}
.mt-toolbar button:hover { background: rgba(255, 255, 255, .22); }

.mt-shell { width: min(1000px, calc(100% - 24px)); margin: 0 auto; padding: 12px 0 24px; }
.mt-title { margin: 4px 0 10px; text-align: center; font-size: clamp(24px, 4vw, 36px); color: var(--mt-gold); text-shadow: 0 3px 0 #6b4a00; }

/* 상태 막대 */
.mt-hud {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  padding: 8px 12px; margin-bottom: 8px; border-radius: 14px; background: rgba(0, 0, 0, .45);
  font-size: 15px;
}
.mt-meter, .mt-stat { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.mt-bar { width: 90px; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.mt-bar i { display: block; height: 100%; width: 100%; border-radius: 6px; transition: width .15s; }
.mt-fuel .mt-bar i { background: linear-gradient(90deg, #ff9a3d, #ffd23d); }
.mt-fuel .mt-bar i.low { background: var(--mt-red); animation: mt-blink .6s infinite alternate; }
.mt-hp .mt-bar i { background: linear-gradient(90deg, #ff5d73, #ff9aa8); }
.mt-meter b { font-size: 13px; min-width: 58px; color: #ffe9c7; }
.mt-stat b.full { color: #ff8a8a; }
.mt-debt b { color: #ff8a8a; }
@keyframes mt-blink { to { opacity: .45; } }

/* 게임판 */
.mt-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden; box-shadow: 0 18px 40px rgba(0, 0, 0, .5); background: #000; }
.mt-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.mt-toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  max-width: min(560px, calc(100% - 140px)); padding: 9px 14px; border-radius: 12px;
  background: rgba(20, 16, 12, .88); color: #fff; font-weight: 700; font-size: 14px; text-align: center;
  pointer-events: none; box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
}
.mt-help { margin: 10px 0 0; text-align: center; color: #d8c8b2; font-size: 14px; }
.mt-rotate-hint { display: none; text-align: center; color: #ffe9a8; font-weight: 700; }

/* 가게 창 */
.mt-panel {
  position: absolute; top: 10px; right: 10px; width: min(330px, calc(100% - 120px)); max-height: calc(100% - 20px);
  overflow: auto; padding: 14px; border-radius: 16px; background: var(--mt-panel); color: var(--mt-ink);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
.mt-panel header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mt-panel h2 { margin: 0; font-size: 19px; }
.mt-panel header button { border: 0; background: #eee5d6; border-radius: 8px; width: 30px; height: 30px; cursor: pointer; }
.mt-panel p { margin: 8px 0; line-height: 1.45; }
.mt-muted { color: var(--mt-muted); font-size: 13px; }
.mt-warn { padding: 8px 10px; border-radius: 10px; background: #ffecec; color: #b42323; font-size: 13px; font-weight: 700; }
.mt-ore-list { list-style: none; margin: 0 0 10px; padding: 0; }
.mt-ore-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--mt-line); }
.mt-ore-list span { flex: 1; }
.mt-ore-dot { width: 12px; height: 12px; border-radius: 3px; transform: rotate(45deg); border: 1px solid rgba(0, 0, 0, .25); }
.mt-shop-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--mt-line); }
.mt-shop-info { flex: 1; display: grid; gap: 2px; }
.mt-shop-info small { color: var(--mt-muted); font-size: 12px; line-height: 1.35; }
.mt-buy { border: 0; border-radius: 10px; padding: 8px 10px; min-width: 82px; cursor: pointer; font-weight: 800; background: var(--mt-gold); color: #3b2a00; }
.mt-buy:disabled { background: #e4ddd1; color: #9a9182; cursor: not-allowed; }
.mt-reset { margin-top: 14px; width: 100%; border: 0; border-radius: 10px; padding: 9px; cursor: pointer; background: #ffecec; color: #b42323; font-weight: 800; }

/* 버튼 공통 */
.mt-primary, .mt-secondary { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 800; cursor: pointer; }
.mt-primary { background: linear-gradient(135deg, #ffd23d, #f5a518); color: #3b2a00; box-shadow: 0 4px 0 var(--mt-gold-dark); }
.mt-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--mt-gold-dark); }
.mt-primary:disabled { background: #e4ddd1; color: #9a9182; box-shadow: none; cursor: not-allowed; }
.mt-secondary { background: #eee5d6; color: #4b4030; }
.mt-wide { width: 100%; }
.mt-primary:focus-visible, .mt-secondary:focus-visible, .mt-buy:focus-visible { outline: 3px solid #4f8cff; outline-offset: 2px; }

/* 창(시작·멈춤·확인·엔딩·순위) */
.mt-modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(10, 7, 4, .7); }
.mt-card {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 24px;
  border-radius: 22px; background: var(--mt-panel); color: var(--mt-ink); text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.mt-card h2 { margin: 6px 0 10px; }
.mt-card p { line-height: 1.55; color: #4a4558; }
.mt-card label { display: block; margin: 14px 0 6px; font-weight: 800; text-align: left; }
.mt-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1.5px solid #d9cfbf; border-radius: 12px;
  background: #fff; color: var(--mt-ink); outline: none;
}
.mt-card input:focus { border-color: var(--mt-gold-dark); box-shadow: 0 0 0 3px rgba(245, 197, 24, .3); }
.mt-card .mt-primary { width: 100%; }
.mt-card-emoji { font-size: 48px; }
.mt-notice { padding: 10px; border-radius: 10px; background: #fff3cf; color: #7a5a00 !important; font-weight: 700; }
.mt-save-info { padding: 10px; border-radius: 10px; background: #f2ebdf; font-weight: 700; }
#mtContinueBox { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px dashed #d9cfbf; }
.mt-row { display: flex; gap: 10px; }
.mt-row > * { flex: 1; }
/* 📍 지정 워프석 */
.mt-warp-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; text-align: left; max-height: 50dvh; overflow-y: auto; }
.mt-warp-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: #f2ebdf; }
.mt-warp-list li span { flex: 1; font-weight: 700; }
.mt-warp-list li .mt-buy { min-width: 0; }
.mt-warp-list li .mt-drop { background: #eee5d6; color: #8a3b2b; }
.mt-warp-card .mt-secondary.mt-wide { width: 100%; margin-top: 12px; }
/* 📱 다른 기기 연동 */
.mt-link-worlds { margin-top: 16px; text-align: left; }
.mt-link-worlds-head { margin: 0 0 8px; font-weight: 800; }
.mt-link-worlds ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mt-link-worlds li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #e9f1ff; }
.mt-link-worlds li span { flex: 1; font-weight: 700; font-size: 14px; }
.mt-link-worlds li .mt-buy { flex: none; }
.mt-link-card .mt-secondary.mt-wide { width: 100%; margin-top: 10px; }
.mt-link-card form .mt-primary { margin-top: 14px; }
#mtJoinForm .mt-row { margin-top: 14px; }
.mt-taken-compare li { gap: 12px; border-bottom-color: #e8dfcf; }
.mt-taken-compare span { flex: none; white-space: nowrap; }

/* 👫 친구와 함께 */
.mt-multi-card .mt-secondary.mt-wide { width: 100%; margin-top: 10px; }
.mt-multi-or { margin: 16px 0 8px; }
/* 코드 칸은 위에 크게, 놀러 가기 단추는 아래에(옆에 두면 .mt-card .mt-primary의 width: 100% 때문에 칸이 손톱만 해져 쓴 글자가 안 보였음) */
.mt-multi-join { display: grid; gap: 10px; }
.mt-multi-join input { width: 100%; margin: 0; padding: 12px; font-size: 28px; font-weight: 900; letter-spacing: .3em; text-align: center; text-transform: uppercase; }
.mt-multi-join input::placeholder { font-size: 18px; font-weight: 700; letter-spacing: .1em; color: #b8ad9c; }
.mt-multi-code-label { margin: 0; font-weight: 800; color: var(--mt-muted); }
.mt-multi-code { margin: 2px 0 8px; font-size: 44px; font-weight: 900; letter-spacing: .25em; user-select: all; }
.mt-multi-players { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.mt-multi-players li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: #f2ebdf; font-weight: 700; }
.mt-multi-players li i { flex: none; width: 14px; height: 14px; border-radius: 4px; }
.mt-multi-players li small { margin-left: auto; color: var(--mt-muted); font-weight: 700; }
.mt-taken-compare b { white-space: normal; text-align: right; }
.mt-ending { background: linear-gradient(160deg, #fffaf2, #fff1c2); }

/* 순위 */
.mt-tabs { display: flex; gap: 6px; margin: 8px 0; }
.mt-tabs button { flex: 1; border: 0; border-radius: 10px; padding: 9px; cursor: pointer; background: #eee5d6; color: #4b4030; font-weight: 800; }
.mt-tabs button.active { background: var(--mt-gold); color: #3b2a00; }
.mt-rank-note { font-size: 13px; margin: 6px 0; }
.mt-rank-list { list-style: none; margin: 0 0 14px; padding: 0; text-align: left; }
.mt-rank-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.mt-rank-row:nth-child(odd) { background: #f6efe3; }
.mt-rank-badge { min-width: 38px; font-weight: 900; color: #8a7a60; }
.mt-rank-1 .mt-rank-badge { color: #d4a000; }
.mt-rank-2 .mt-rank-badge { color: #8f9aa8; }
.mt-rank-3 .mt-rank-badge { color: #c0763a; }
.mt-rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-rank-empty { padding: 18px; text-align: center; color: var(--mt-muted); }

/* 터치 단추: 손가락 화면에서만 */
.mt-touch { display: none; }
@media (pointer: coarse) {
  .mt-touch { display: block; position: absolute; inset: 0; pointer-events: none; }
  .mt-touch button {
    pointer-events: auto; position: absolute; width: 58px; height: 58px; border: 0; border-radius: 16px;
    background: rgba(255, 255, 255, .22); color: #fff; font-size: 22px; font-weight: 900;
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  }
  .mt-touch button.on { background: rgba(245, 197, 24, .7); }
  .mt-pad { position: absolute; left: 12px; bottom: 12px; width: 186px; height: 128px; }
  .mt-up { left: 64px; top: 0; }
  .mt-left { left: 0; bottom: 0; }
  .mt-down { left: 64px; bottom: 0; }
  .mt-right { left: 128px; bottom: 0; }
  .mt-up, .mt-down { height: 60px !important; }
  .mt-touch-right { position: absolute; right: 12px; bottom: 12px; width: 58px; height: 124px; }
  .mt-panel { right: 80px; }
  .mt-touch-right button:first-child { bottom: 66px; }
  .mt-touch-right button:last-child { bottom: 0; }
}

/* 좁은 화면 */
@media (max-width: 640px) {
  .mt-hud { font-size: 13px; gap: 4px 10px; }
  .mt-bar { width: 60px; }
  .mt-panel { width: calc(100% - 20px); }
}
@media (max-width: 640px) and (orientation: portrait) {
  .mt-rotate-hint { display: block; }
}
/* 가로 휴대폰: 제목·안내를 숨기고 게임판을 화면 높이에 맞춘다 */
@media (max-height: 500px) and (orientation: landscape) {
  .mt-toolbar { padding: 4px 10px; }
  .mt-toolbar button { padding: 4px 8px; font-size: 13px; }
  .mt-title, .mt-help, .mt-rotate-hint { display: none; }
  .mt-shell { padding: 4px 0; width: calc(100% - 12px); }
  .mt-hud { font-size: 12px; padding: 4px 8px; margin-bottom: 4px; gap: 2px 8px; }
  .mt-meter b { min-width: 46px; font-size: 11px; }
  .mt-bar { width: 50px; height: 9px; }
  .mt-stage { width: auto; max-width: 100%; height: calc(100vh - 78px); margin: 0 auto; }
  .mt-panel { width: min(300px, calc(100% - 150px)); }
}
@media (prefers-reduced-motion: reduce) {
  .mt-fuel .mt-bar i.low { animation: none; }
  .mt-bar i { transition: none; }
}

/* ===== 2차 업데이트: 지각 밑·자동 드릴·지구 파괴 ===== */
.mt-shop-head { margin: 14px 0 2px; font-size: 14px; color: #8a7a60; }
.mt-locked { opacity: .55; }
.mt-locked .mt-buy { background: #e4ddd1; }
.mt-stat b.hot { color: #ff9a5a; animation: mt-blink .5s infinite alternate; }
.mt-badge { display: inline-block; padding: 6px 12px; border-radius: 999px; background: #1f2a5a; color: #fff !important; font-weight: 800; }
.mt-open-news { padding: 10px; border-radius: 10px; background: #fff0e0; color: #8a3a00 !important; }
.mt-destroy { background: linear-gradient(160deg, #1b1640, #3a1030); color: #fff; }
.mt-destroy p, .mt-destroy h2 { color: #fff; }
.mt-destroy-stats { list-style: none; padding: 0; margin: 10px 0; text-align: left; }
.mt-destroy-stats li { display: flex; justify-content: space-between; padding: 7px 10px; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.mt-destroy .mt-secondary { background: rgba(255, 255, 255, .15); color: #fff; }
@media (pointer: coarse) {
  /* 💥 🌀 / 📍 💸 를 2×2로 둔다(네 개를 세로로 쌓으면 가로 휴대폰에서 너무 길어서) */
  .mt-touch-right { width: 124px; height: 124px; }
  .mt-touch-right button:nth-child(1) { left: 0; bottom: 66px; }
  .mt-touch-right button:nth-child(2) { right: 0; bottom: 66px; }
  .mt-touch-right button:nth-child(3) { left: 0; bottom: 0; }
  .mt-touch-right button:nth-child(4) { right: 0; bottom: 0; }
  .mt-panel { right: 146px; }
}
@media (prefers-reduced-motion: reduce) {
  .mt-stat b.hot { animation: none; }
}

/* ===== 3차 업데이트: 설명 창·뽑기·히든 엔딩 ===== */
.mt-guide { width: min(560px, 100%); text-align: left; }
.mt-guide .mt-card-emoji, .mt-guide h2 { text-align: center; }
.mt-guide h3 { margin: 16px 0 6px; font-size: 16px; }
.mt-guide p { margin: 0 0 6px; }
.mt-guide-list { margin: 0; padding-left: 20px; line-height: 1.6; color: #4a4558; }
.mt-guide-ores { width: 100%; border-collapse: collapse; font-size: 14px; }
.mt-guide-ores th, .mt-guide-ores td { padding: 5px 8px; border-bottom: 1px solid #eadfcd; text-align: left; }
.mt-guide-ores td:last-child, .mt-guide-ores th:last-child { text-align: right; font-weight: 800; }
.mt-guide-ores tr.mt-guide-layer td { background: #f2ebdf; color: #8a7a60; font-weight: 800; }
.mt-guide .mt-primary { margin-top: 16px; }
.mt-gacha-odds { display: block; margin-top: 2px; color: #8a7a60; }
.mt-hidden-ending { background: linear-gradient(160deg, #f3f0ff, #d9f7ff); }
.mt-guide-ores .mt-ore-dot { display: inline-block; margin-right: 4px; vertical-align: -1px; }
.mt-guide-ores tr.mt-guide-layer td { text-align: left; }

/* ===== 휴대폰 화면 맞춤(세로): 게임판 밖으로 조작 단추를 내리고, 가게 창을 화면 아래 시트로 ===== */
@media (max-width: 640px) and (orientation: portrait) {
  .mt-stage { overflow: visible; }
  .mt-stage canvas { border-radius: 16px; }
  .mt-stage .mt-touch { inset: auto; left: 0; right: 0; top: 100%; height: 206px; margin-top: 8px; }
  .mt-panel {
    position: fixed; left: 8px; right: 8px; top: auto; bottom: 8px; width: auto;
    max-height: 70vh; max-height: 70dvh; z-index: 15;
  }
  .mt-toast { max-width: calc(100% - 24px); font-size: 13px; }
  .mt-help { display: none; }
}
/* 주소창이 줄었다 늘었다 하는 휴대폰: 보이는 높이(dvh)를 쓴다 */
@supports (height: 100dvh) {
  .mt-card { max-height: calc(100dvh - 32px); }
  @media (max-height: 500px) and (orientation: landscape) {
    .mt-stage { height: calc(100dvh - 78px); }
  }
}
@media (pointer: coarse) and (max-width: 640px) and (orientation: portrait) {
  .mt-stage { margin-bottom: 214px; }
}

/* ⚔️ 팀전 */
.mt-team-open { width: 100%; margin-top: 12px; }
.mt-team-open small { display: block; font-weight: 600; opacity: .75; }
.mt-team-label { margin: 12px 0 6px; font-weight: 800; text-align: left; }
.mt-team-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.mt-team-pick button { flex: 1 1 0; min-width: 72px; padding: 10px 8px; border: 2px solid transparent; border-radius: 12px; background: #f2ebdf; font: inherit; font-weight: 800; cursor: pointer; }
.mt-team-pick button.on { border-color: var(--team, #6c4ff6); background: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--team, #6c4ff6) 25%, transparent); }
.mt-team-pick button small { display: block; font-weight: 600; opacity: .7; }
.mt-team-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; text-align: left; }
.mt-team-col { padding: 10px; border-radius: 14px; background: #f7f1e7; border-top: 5px solid var(--team); }
.mt-team-col.mine { background: #fff; box-shadow: 0 0 0 2px var(--team); }
.mt-team-col h3 { margin: 0 0 6px; font-size: 16px; }
.mt-team-col ul { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; font-weight: 700; font-size: 14px; }
.mt-team-col li small { opacity: .7; font-weight: 600; }
.mt-team-col button { width: 100%; padding: 6px; border: 0; border-radius: 10px; background: var(--team); color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.mt-team-card { max-height: 92dvh; overflow: auto; }

/* ⚔️ 팀전 열린 방 목록 */
.mt-team-refresh { margin-left: 6px; padding: 2px 8px; border: 0; border-radius: 8px; background: #eee5d6; font: inherit; cursor: pointer; }
.mt-team-rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 210px; overflow: auto; text-align: left; }
.mt-team-rooms li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: #f2ebdf; }
.mt-team-rooms li.on { background: #fff; box-shadow: 0 0 0 2px #6c4ff6; }
.mt-team-rooms li > div { flex: 1; min-width: 0; }
.mt-team-rooms li b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-team-rooms li small { font-weight: 700; opacity: .8; }
.mt-team-rooms li button { flex: none; padding: 8px 12px; border: 0; border-radius: 10px; background: #6c4ff6; color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.mt-team-rooms .mt-team-empty { justify-content: center; color: #8a7d68; font-weight: 700; }

.mt-team-code { grid-template-columns: 1fr auto; margin-top: 8px; }
.mt-team-code input { font-size: 18px; letter-spacing: .15em; padding: 8px; }
.mt-team-new { margin-top: 18px; padding-top: 12px; border-top: 2px dashed #e4d8c4; }
