/* ==========================================================
   ぐらぐら どうぶつタワー - スタイル
   ========================================================== */
:root {
    --cream: #fff4dc;
    --paper: #fffaf0;
    --ink: #5a3d2b;
    --ink-soft: #8a6a52;
    --orange: #ff9f43;
    --orange-dark: #e07b17;
    --green: #6cc070;
    --green-dark: #3f9a48;
    --blue: #6ab7ff;
    --pink: #ff8fab;
    --hud-h: 56px;
    --ctrl-h: 88px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--cream);
    background-image:
        radial-gradient(circle at 20% 20%, rgba(255, 200, 120, .25) 0 8%, transparent 9%),
        radial-gradient(circle at 80% 70%, rgba(150, 210, 255, .25) 0 10%, transparent 11%);
    font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'M PLUS Rounded 1c', sans-serif;
    color: var(--ink);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

button {
    font-family: inherit;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

#app {
    position: relative;
    width: min(440px, 100vw);
    height: 100vh;
    height: 100dvh;
    max-height: 860px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

@media (min-height: 860px) {
    #app { top: 50%; transform: translateY(-50%); }
}

/* ---------- HUD ---------- */
#hud {
    height: var(--hud-h);
    flex: 0 0 var(--hud-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 8px;
}

.hud-stats {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.stat {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 2px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 14px 18px 12px 16px;
    padding: 5px 4px;
    font-size: 14px;
    white-space: nowrap;
    box-shadow: 0 3px 0 rgba(90, 61, 43, .25);
}

.stat b {
    font-size: 18px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.stat small {
    font-size: 11px;
    font-weight: 700;
    color: var(--ink-soft);
}

.stat.bump { animation: bump .35s ease; }

@keyframes bump {
    40% { transform: scale(1.18) rotate(-3deg); }
}

.hud-buttons {
    display: flex;
    gap: 4px;
}

.icon-btn {
    height: 40px;
    min-width: 40px;
    border: 3px solid var(--ink);
    background: #fff;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0 6px;
    box-shadow: 0 3px 0 rgba(90, 61, 43, .25);
}

.icon-btn span { font-size: 11px; }
.icon-btn.off { background: #eee; color: #999; }
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

/* ---------- Stage ---------- */
#stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game {
    display: block;
    border: 4px solid var(--ink);
    border-radius: 22px 26px 20px 24px;
    box-shadow: 0 6px 0 rgba(90, 61, 43, .25);
    touch-action: none;
    background: #cdeeff;
    cursor: grab;
}

#game:active { cursor: grabbing; }

/* ---------- Controls（回転ボタンのみ） ---------- */
#controls {
    flex: 0 0 var(--ctrl-h);
    height: var(--ctrl-h);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 8px 16px 12px;
    transition: transform .25s ease, opacity .25s ease;
}

/* タイトル画面表示中はコントロールUIを完全に非表示 */
body.in-title #controls {
    display: none !important;
}

.ctrl-btn {
    border: 4px solid var(--ink);
    border-radius: 22px;
    background: #fff;
    font-weight: 900;
    font-size: 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 5px 0 var(--ink);
    transition: transform .05s, box-shadow .05s, opacity .2s;
    touch-action: none;
}

.ctrl-btn i { font-size: 22px; }

.ctrl-btn.rot {
    background: #d9f0ff;
    color: var(--ink);
}

.ctrl-btn:active,
.ctrl-btn.pressed {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--ink);
}

.ctrl-btn:disabled,
.ctrl-btn.locked {
    opacity: .45;
}

/* ---------- Overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(255, 244, 220, .55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    z-index: 10;
}

.overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.overlay.modal { z-index: 20; background: rgba(90, 61, 43, .35); }

.panel {
    position: relative;
    width: min(360px, 100%);
    max-height: 94%;
    overflow-y: auto;
    background: var(--paper);
    border: 4px solid var(--ink);
    border-radius: 28px 32px 26px 30px;
    padding: 18px 18px 16px;
    text-align: center;
    box-shadow: 0 8px 0 rgba(90, 61, 43, .3);
    transform: scale(.9) translateY(10px);
    transition: transform .3s cubic-bezier(.2, 1.6, .4, 1);
}

.overlay.show .panel { transform: none; }

/* ---------- タイトル画面デザイン ---------- */
.title-panel {
    width: min(380px, 96%);
    padding: 18px 16px 16px;
    border-radius: 32px;
}

.title-badge {
    display: inline-block;
    background: #ffe3a8;
    color: #925c1f;
    font-size: 11px;
    font-weight: 900;
    padding: 3px 14px;
    border-radius: 999px;
    border: 2px solid var(--ink);
    margin-bottom: 6px;
    letter-spacing: 1px;
}

.logo {
    margin: 0 0 4px;
    line-height: 1.05;
}

.logo-sub {
    display: inline-block;
    font-size: 22px;
    color: var(--orange);
    letter-spacing: 4px;
    animation: wobble 1.6s ease-in-out infinite;
    -webkit-text-stroke: 1px var(--ink);
}

.logo-main {
    display: block;
    font-size: 34px;
    font-weight: 900;
    color: var(--green);
    -webkit-text-stroke: 1.5px var(--ink);
    text-shadow: 0 3px 0 rgba(90, 61, 43, .3);
}

@keyframes wobble {
    0%, 100% { transform: rotate(-4deg); }
    50% { transform: rotate(4deg); }
}

.title-stage-art {
    margin: 6px 0 10px;
    border-radius: 20px;
    background: linear-gradient(180deg, #dcf2ff 0%, #fffbf0 100%);
    border: 3px solid var(--ink);
    overflow: hidden;
    padding: 4px 0 0;
    box-shadow: inset 0 2px 6px rgba(90, 61, 43, .1);
}

#title-animals {
    width: 100%;
    height: auto;
    display: block;
}

.title-action-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.title-btn-row {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 1fr;
    gap: 6px;
}

.start-pulse {
    animation: pulse-grow 2.2s ease-in-out infinite;
}

@keyframes pulse-grow {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.025); }
}

.big-btn {
    width: 100%;
    border: 4px solid var(--ink);
    background: var(--green);
    color: #fff;
    font-size: 22px;
    font-weight: 900;
    border-radius: 20px;
    padding: 12px;
    box-shadow: 0 5px 0 var(--ink);
    text-shadow: 0 2px 0 var(--green-dark);
}

.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.best-line {
    margin: 10px 0 0;
    font-size: 14px;
    font-weight: 800;
    color: var(--ink-soft);
}

.best-line b {
    color: var(--orange-dark);
    font-size: 17px;
}

/* ---------- ルール一覧モーダル ---------- */
.rules-panel {
    width: min(380px, 96%);
    padding: 18px 14px 14px;
}

.modal-title {
    margin: 0 0 12px;
    font-size: 22px;
    font-weight: 900;
    color: var(--ink);
}

.rules-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 12px;
    text-align: left;
}

.rule-card {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 3px solid var(--ink);
    border-radius: 16px;
    padding: 7px 10px;
    box-shadow: 0 2px 0 rgba(90, 61, 43, .15);
}

.rule-icon {
    font-size: 24px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.rule-text b {
    display: block;
    font-size: 13.5px;
    font-weight: 900;
    color: var(--ink);
}

.rule-text p {
    margin: 1px 0 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--ink-soft);
    line-height: 1.35;
}

.ok-btn {
    font-size: 18px;
    padding: 9px;
}

/* ---------- 設定モーダル ---------- */
.settings-panel {
    width: min(380px, 96%);
    padding: 18px 16px 14px;
    text-align: left;
}

.settings-panel .modal-title {
    text-align: center;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fff;
    border: 3px solid var(--ink);
    border-radius: 18px;
    padding: 12px 14px;
    box-shadow: 0 3px 0 rgba(90, 61, 43, .15);
    margin-bottom: 12px;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13.5px;
    font-weight: 900;
    color: var(--ink);
}

.setting-label i {
    color: var(--orange);
    margin-right: 4px;
}

.setting-label b {
    color: var(--orange-dark);
    font-size: 14px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    background: #eee;
    border: 2px solid var(--ink);
    border-radius: 999px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: var(--orange);
    border: 3px solid var(--ink);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(90, 61, 43, .2);
}

.btn-toggle-group {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.toggle-btn {
    border: 3px solid var(--ink);
    background: #fff;
    border-radius: 12px;
    padding: 6px 2px;
    font-size: 12px;
    font-weight: 900;
    color: var(--ink);
    box-shadow: 0 3px 0 var(--ink);
}

.toggle-btn.active {
    background: var(--green);
    color: #fff;
    text-shadow: 0 1px 0 var(--green-dark);
}

.toggle-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 var(--ink);
}

/* ご意見・ご要望フォーム */
.feedback-box {
    background: #fff8eb;
    border: 3px dashed var(--orange);
    border-radius: 18px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.feedback-title {
    font-size: 13.5px;
    font-weight: 900;
    color: var(--orange-dark);
}

.feedback-title i {
    margin-right: 4px;
}

.feedback-desc {
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--ink-soft);
    line-height: 1.35;
}

.feedback-box textarea {
    width: 100%;
    border: 2.5px solid var(--ink);
    border-radius: 12px;
    padding: 8px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    resize: none;
    outline: none;
    background: #fff;
    -webkit-user-select: text;
    user-select: text;
}

.feedback-send-btn {
    background: var(--orange) !important;
    color: #fff !important;
    text-shadow: 0 1px 0 var(--orange-dark);
    padding: 7px;
    font-size: 13px;
    border-radius: 12px;
}

.feedback-send-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: 0 2px 0 var(--ink) !important;
}

/* ---------- リザルト画面 ---------- */
.result-title {
    margin: 0;
    font-size: 26px;
    font-weight: 900;
    color: var(--pink);
    -webkit-text-stroke: 1px var(--ink);
}

.result-title.clear { color: var(--orange); }

.result-sub {
    margin: 4px 0 10px;
    font-weight: 700;
    font-size: 14px;
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.result-stats > div {
    background: #fff;
    border: 3px solid var(--ink);
    border-radius: 16px;
    padding: 6px;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 3px;
}

.result-stats b { font-size: 24px; font-weight: 900; }
.result-stats small { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.result-stats .score { grid-column: span 2; background: #fff3c4; }
.result-stats .score b { font-size: 34px; color: var(--orange-dark); }

.res-best {
    min-height: 1.2em;
    margin: 8px 0;
    font-weight: 900;
    color: var(--orange-dark);
}

.res-best.new { animation: bump .6s ease infinite alternate; }

.name-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 900;
    font-size: 14px;
}

.name-field input {
    flex: 1;
    min-width: 0;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    border: 3px solid var(--ink);
    border-radius: 12px;
    padding: 6px 10px;
    background: #fff;
    -webkit-user-select: text;
    user-select: text;
}

.result-buttons { display: flex; flex-direction: column; gap: 8px; }
.result-buttons .action-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.result-buttons .action-row.has-continue {
    grid-template-columns: 1.18fr 1fr;
    gap: 6px;
}

.result-buttons .action-row.has-continue .big-btn {
    font-size: 15.5px;
    padding: 10px 4px;
    white-space: nowrap;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.continue-btn {
    background: #ff9f43 !important;
    text-shadow: 0 2px 0 #d97706 !important;
    animation: pulse-grow 2s ease-in-out infinite;
}

.result-buttons .row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.sub-btn {
    border: 3px solid var(--ink);
    background: #fff;
    border-radius: 16px;
    padding: 9px 4px;
    font-weight: 900;
    font-size: 13.5px;
    box-shadow: 0 4px 0 var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.sub-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.result-buttons .row .sub-btn {
    font-size: 11.5px;
    padding: 8px 1px;
    white-space: nowrap;
    word-break: keep-all;
    gap: 3px;
}

/* ---------- ランキング ---------- */
.ranking-title { margin: 0 0 10px; font-size: 24px; font-weight: 900; }

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: 3px solid var(--ink);
    background: #fff;
    border-radius: 50%;
    font-size: 16px;
}

.ranking-list {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
    text-align: left;
}

.ranking-list li {
    display: grid;
    grid-template-columns: 34px 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 2px dashed rgba(90, 61, 43, .2);
    font-weight: 700;
}

.ranking-list li.me { background: #fff3c4; border-radius: 10px; }

.ranking-list .rank {
    font-size: 18px;
    font-weight: 900;
    text-align: center;
}

.ranking-list .who { min-width: 0; }
.ranking-list .who .nm { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-list .who .meta {
    display: block;
    font-size: 10.5px;
    color: var(--ink-soft);
    white-space: nowrap;
}
.ranking-list .pts { font-size: 18px; font-weight: 900; color: var(--orange-dark); }
.ranking-list .empty { display: block; text-align: center; color: var(--ink-soft); border: none; padding: 20px 0; }

.ranking-reset-note {
    margin: 10px 0 0;
    font-size: 11.5px;
    font-weight: 800;
    color: var(--ink-soft);
    text-align: center;
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 10px;
    padding: 6px;
}

.ranking-reset-note i {
    color: var(--orange-dark);
    margin-right: 4px;
}

/* ---------- トースト ---------- */
.toast {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translate(-50%, 20px);
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transition: all .25s;
    z-index: 30;
    white-space: nowrap;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 600px) {
    :root { --hud-h: 48px; --ctrl-h: 76px; }
    .ctrl-btn i { font-size: 20px; }
    .stat b { font-size: 16px; }
}
