/* 全体のリセットと背景設定 */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #0a0a0a;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

button,
#game-canvas,
#mobile-controls,
#interaction-hint,
#message-window,
#scene-container,
#work-player {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-drag: none;
    user-drag: none;
}

input,
textarea {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    background-color: #111;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

#ui-layer {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    pointer-events: none;
    text-shadow: 1px 1px 2px #000;
    z-index: 50;
}

#scene-name {
    font-weight: bold;
    font-size: 18px;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 4px;
}

#debug-info {
    display: inline-block;
    margin-top: 5px;
    background: rgba(200, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 4px;
}

#clicked-coord {
    color: #ffaa00;
    font-weight: bold;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.8);
    padding: 4px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 5px;
}

#area-title {
    position: absolute;
    left: 50%;
    top: max(20%, calc(20px + env(safe-area-inset-top)));
    transform: translateX(-50%) translateY(15px);
    text-align: center;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    opacity: 0;
    pointer-events: none;
    z-index: 70;
    transition: opacity 0.8s ease, transform 0.8s ease;
}

#area-title.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#area-title-main {
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

#area-title-sub {
    font-size: 14px;
    color: #ddd;
    letter-spacing: 1px;
}

#interaction-hint {
    position: absolute;
    left: 50%;
    bottom: calc(162px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(10px);
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(10, 16, 24, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 12px;
}

#interaction-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
    cursor: pointer;
}

#interaction-label {
    font-weight: bold;
    font-size: 15px;
}

#interaction-action {
    font-size: 12px;
    color: #ccc;
    background: rgba(255, 255, 255, 0.15);
    padding: 3px 8px;
    border-radius: 12px;
}

#message-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.12);
    display: none;
    pointer-events: auto;
    touch-action: none;
}

#message-window {
    position: fixed;
    bottom: calc(180px + env(safe-area-inset-bottom));
    left: 20px;
    right: 20px;
    background: rgba(10, 15, 30, 0.85);
    color: #fff;
    border: 2px solid #ccc;
    border-radius: 8px;
    padding: 15px;
    font-size: 16px;
    line-height: 1.5;
    display: none;
    z-index: 90;
    cursor: pointer;
    pointer-events: auto;
    touch-action: none;
}

#mobile-controls {
    position: absolute;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    height: 108px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    pointer-events: none;
    z-index: 80;
    transition: opacity 0.2s ease;
}

#mobile-controls.disabled {
    opacity: 0;
    pointer-events: none;
}

/* 36pxボタンを108pxの正方形へ収める。
   中央の36pxは空白のままで、誤タップを避ける。 */
#dpad {
    position: relative;
    width: 108px;
    height: 108px;
    pointer-events: auto;
    opacity: 0.55;
    transition: opacity 0.2s;
}

#dpad:active {
    opacity: 1;
}

.dpad-btn {
    position: absolute;
    width: 36px;
    height: 36px;
    background: rgba(20, 20, 20, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 9px;
    font-size: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    touch-action: none;
    -webkit-touch-callout: none;
}

.dpad-btn:active,
.dpad-btn.pressed {
    background: rgba(255, 255, 255, 0.4);
}

.up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.left {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.right {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

#action-btns {
    display: flex;
    align-items: flex-end;
    padding-bottom: 10px;
}

#btn-action {
    pointer-events: auto;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 100, 100, 0.6);
    border: 2px solid rgba(255, 150, 150, 0.6);
    color: white;
    font-size: 14px;
    font-weight: bold;
    touch-action: none;
    transition: background 0.2s, font-size 0.2s;
}

#btn-action:active {
    background: rgba(255, 100, 100, 0.9);
}

#btn-debug-toggle {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    background: rgba(50, 50, 50, 0.8);
    color: #fff;
    border: 1px solid #aaa;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 16px;
    font-weight: bold;
    z-index: 300;
    cursor: pointer;
    touch-action: none;
}

#scene-container {
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 20, 0.65);
    display: none;
    padding: 10px;
    padding-top: max(30px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    box-sizing: border-box;
    z-index: 200;
    overflow-y: auto;
}

.rpg-window {
    background: rgba(15, 25, 40, 0.95);
    border: 2px solid #ddd;
    border-radius: 12px;
    padding: 20px;
    max-width: 400px;
    width: 100%;
    margin: 20px auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8);
    box-sizing: border-box;
    color: #eee;
}

.rpg-window-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 10px;
    margin-bottom: 15px;
    text-align: center;
}

.rpg-title {
    font-size: 22px;
    font-weight: bold;
    color: #fff;
    letter-spacing: 1px;
}

.rpg-subtitle {
    font-size: 12px;
    color: #aaa;
    letter-spacing: 2px;
    margin-top: 4px;
}

.rpg-description {
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 10px;
}

.rpg-flavor {
    font-size: 14px;
    line-height: 1.6;
    color: #999;
    font-style: italic;
    margin-bottom: 20px;
}

.rpg-menu-title {
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 12px;
    text-align: center;
}

.rpg-menu-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rpg-menu-item {
    position: relative;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 15px;
    text-align: left;
    padding: 10px 15px 10px 36px;
    border-radius: 6px;
    cursor: pointer;
    min-height: 44px;
    display: flex;
    align-items: center;
    transition: background 0.2s, border-color 0.2s, transform 0.12s;
}

.rpg-menu-item::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #fff4c8;
    font-weight: 900;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

.rpg-menu-item.rpg-menu-selected {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 244, 200, 0.72);
}

.rpg-menu-item.rpg-menu-selected::before {
    content: "▶";
}

.rpg-menu-item:hover,
.rpg-menu-item:focus-visible {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 244, 200, 0.62);
    outline: none;
}

.rpg-menu-item:active {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(1px);
}

.rpg-menu-item.rpg-back {
    background: rgba(50, 50, 50, 0.8);
    margin-top: 8px;
}

/* 湯間庭新報 / noteカードラック
   タイトル一覧を挟まず、記事の見出しカードをそのまま並べる。 */
#scene-container.newspaper-rack {
    background: rgba(9, 15, 20, 0.80);
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.shinpo-rack {
    width: min(100%, 680px);
    margin: 0 auto;
    padding: 0 6px 28px;
    box-sizing: border-box;
}

.shinpo-rack-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 6px 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}

.shinpo-rack-title {
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
}

.shinpo-rack-subtitle {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
    letter-spacing: 0.18em;
}

.shinpo-rack-back {
    flex: 0 0 auto;
    padding: 7px 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.84);
    font-size: 13px;
    touch-action: manipulation;
}

.shinpo-rack-back:active {
    opacity: 0.55;
}

.shinpo-rack-lead {
    margin: 10px 6px 16px;
    color: rgba(255, 255, 255, 0.74);
    font-size: 13px;
    line-height: 1.55;
}

.note-card-rack-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.note-rack-card {
    position: relative;
    overflow: hidden;
    min-height: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    background: #e9e4d7;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.26);
}

.note-rack-card-frame {
    display: block;
    width: 100%;
    height: clamp(208px, 53vw, 318px);
    border: 0;
    background: #e9e4d7;
    pointer-events: none;
}

.note-rack-card-footer {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-height: 34px;
    padding: 0 12px;
    box-sizing: border-box;
    border-top: 1px solid rgba(35, 43, 51, 0.10);
    background: #f2eee5;
    color: #5a6570;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.note-rack-card-open {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.note-rack-card-open:active {
    background: rgba(23, 39, 50, 0.08);
}

.note-rack-card-open:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.92);
    outline-offset: -4px;
}

.note-rack-card-fallback {
    min-height: 170px;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #f2eee5;
}

.note-rack-fallback-title {
    color: #1c2933;
    font-size: 19px;
    font-weight: 700;
    line-height: 1.45;
}

.note-rack-fallback-date {
    margin-top: 12px;
    color: #68737a;
    font-size: 12px;
}

.note-rack-card-fallback .note-rack-card-footer {
    margin: 16px -20px -20px;
}

.shinpo-rack-empty {
    padding: 26px 20px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.78);
    background: rgba(9, 17, 25, 0.64);
    font-size: 14px;
    line-height: 1.65;
}

/* 湯間庭フレーム
   ゲーム・触れるらくがき・将来の読書室を、町の中の場所として見せる共通の額縁。 */
#work-player {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    background: #080a0d;
    z-index: 500;
    overflow: hidden;
    touch-action: none;
}

#work-player.visible {
    display: flex;
}

/* 上部バーはiframeに重ねず、専用の領域として確保する。 */
#work-player-controls {
    position: relative;
    z-index: 3;
    flex: 0 0 auto;
    min-height: 56px;
    padding:
        calc(env(safe-area-inset-top) + 8px)
        max(10px, env(safe-area-inset-right))
        8px
        max(10px, env(safe-area-inset-left));
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    background: rgba(10, 14, 19, 0.98);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

#work-player-content {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #080a0d;
}

#work-player-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #080a0d;
}


/* スマホの縦長ゲームだけは、最初に店名バーを見せた後で収納する。
   収納中はバーが占めていた高さも返すので、ゲーム本体を少し大きくできる。 */
#work-player-peek-tab {
    position: absolute;
    top: max(7px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    z-index: 6;
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 30px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.20);
    border-radius: 0 0 12px 12px;
    background: rgba(12, 16, 21, 0.84);
    color: rgba(255, 255, 255, 0.92);
    font-size: 19px;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.30);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

#work-player-peek-tab[hidden] {
    display: none !important;
}

#work-player-peek-tab:active {
    opacity: 0.56;
}

@media (max-width: 700px), (max-height: 700px) {
    #work-player[data-player-layout="phone"] #work-player-controls {
        min-height: 0;
        height: calc(env(safe-area-inset-top) + 56px);
        overflow: hidden;
        transition:
            height 260ms ease,
            padding 260ms ease,
            opacity 180ms ease,
            border-color 180ms ease,
            transform 260ms ease;
        will-change: height, transform;
    }

    #work-player[data-player-layout="phone"].phone-controls-hidden #work-player-controls {
        height: 0;
        padding-top: 0;
        padding-bottom: 0;
        border-bottom-color: transparent;
        opacity: 0;
        transform: translateY(-10px);
        pointer-events: none;
    }

    #work-player[data-player-layout="phone"].phone-controls-hidden #work-player-content {
        padding-top: 0;
        padding-bottom: 0;
    }

    #work-player[data-player-layout="phone"].phone-controls-hidden #work-player-peek-tab:not([hidden]) {
        display: inline-flex;
    }
}


/* 縦長ゲーム用の「携帯ゲーム画面」。
   PCやiPadでは横に引き伸ばさず、iPhone相当の比率を中央に残す。 */
#work-player[data-player-layout="phone"] #work-player-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
    background:
        radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.055), transparent 44%),
        #080a0d;
}

#work-player[data-player-layout="phone"] #work-player-frame {
    position: relative;
    inset: auto;
    flex: 0 0 auto;
    width: var(--town-player-render-width, 390px);
    height: var(--town-player-render-height, 844px);
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 18px;
    box-sizing: border-box;
    background: #0b0b0d;
    box-shadow:
        0 16px 36px rgba(0, 0, 0, 0.48),
        0 0 0 5px rgba(255, 255, 255, 0.035);
}

@media (max-width: 480px) {
    #work-player[data-player-layout="phone"] #work-player-content {
        padding: 8px;
    }

    #work-player[data-player-layout="phone"] #work-player-frame {
        border-radius: 14px;
    }
}

#work-player-loading {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: none;
    align-items: center;
    justify-content: center;
    background: #080a0d;
    pointer-events: auto;
}

#work-player-loading.visible {
    display: flex;
}

.work-player-loading-card {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 14px;
    letter-spacing: 0.04em;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(17, 23, 31, 0.88);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32);
}

.work-player-loading-mark {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.22);
    border-top-color: rgba(255, 255, 255, 0.92);
    border-radius: 50%;
    animation: work-player-spin 0.8s linear infinite;
}

@keyframes work-player-spin {
    to {
        transform: rotate(360deg);
    }
}

#btn-close-work {
    justify-self: start;
    min-width: 0;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.town-frame-back-arrow {
    flex: 0 0 auto;
    font-size: 20px;
    line-height: 0.8;
    font-weight: 400;
}

#work-player-return-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

#btn-close-work:active {
    opacity: 0.55;
}

#work-player-title {
    justify-self: stretch;
    min-width: 0;
    color: rgba(255, 255, 255, 0.94);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.04em;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

#btn-open-frame-source {
    justify-self: end;
    min-width: 0;
    max-width: 100%;
    padding: 6px 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.76);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

#btn-open-frame-source:active {
    opacity: 0.55;
}

/* 将来の触れるらくがき向け。
   現在はstandardと同じ高さを保ちつつ、少し柔らかい見た目だけ用意する。 */
#work-player[data-frame-mode="soft"] #work-player-controls {
    background: rgba(11, 15, 20, 0.88);
    border-bottom-color: rgba(255, 255, 255, 0.09);
    box-shadow: none;
}

#work-player[data-frame-mode="soft"] #work-player-title {
    color: rgba(255, 255, 255, 0.82);
    font-weight: 600;
}

#work-player[data-frame-mode="reader"] {
    background: #e9e4d7;
}

#work-player[data-frame-mode="reader"] #work-player-controls {
    background: #24313a;
    border-bottom-color: rgba(255, 255, 255, 0.18);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
}

#work-player[data-frame-mode="reader"] #work-player-content,
#work-player[data-frame-mode="reader"] #work-player-frame,
#work-player[data-frame-mode="reader"] #work-player-loading {
    background: #e9e4d7;
}

#work-player[data-frame-mode="reader"] #work-player-title {
    color: rgba(255, 255, 255, 0.96);
}

#work-player[data-frame-mode="reader"] #btn-open-frame-source {
    color: rgba(255, 255, 255, 0.84);
}

/* noteの埋め込み表示は自前のページとは異なり縦スクロールが必要。 */
#work-player[data-frame-mode="reader"] #work-player-frame {
    overflow: auto;
}

#editor-panel {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    width: 280px;
    /* Content-box limits reserve both safe-area margins and the 2px borders. */
    max-width: calc(100vw - max(10px, env(safe-area-inset-left)) - max(10px, env(safe-area-inset-right)) - 4px);
    max-height: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)) - 4px);
    background: rgba(20, 20, 25, 0.95);
    border: 2px solid #666;
    border-radius: 8px;
    z-index: 350;
    flex-direction: column;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.editor-header {
    flex-shrink: 0;
    background: #333;
    padding: 10px;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
}

.editor-header button {
    flex-shrink: 0;
    background: transparent;
    color: white;
    border: none;
    font-size: 16px;
    padding: 5px;
}

.editor-content {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 10px;
    font-size: 14px;
}

.editor-content label {
    display: block;
    margin-bottom: 8px;
}

.editor-content select,
.editor-content input {
    width: 100%;
    padding: 6px;
    margin-top: 4px;
    background: #222;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
    box-sizing: border-box;
}

.editor-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
}

.editor-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    margin: 0 5px;
}

#export-modal {
    position: absolute;
    top: 5%;
    left: 5%;
    right: 5%;
    bottom: 5%;
    background: #111;
    border: 2px solid #888;
    border-radius: 8px;
    z-index: 400;
    flex-direction: column;
    padding: 10px;
}

.export-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.export-header button {
    background: #555;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
}

#export-textarea {
    flex: 1;
    width: 100%;
    background: #222;
    color: #0f0;
    border: 1px solid #555;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    resize: none;
    box-sizing: border-box;
}

#btn-copy-export {
    margin-top: 10px;
    background: #38f;
    color: white;
    border: none;
    padding: 15px;
    font-size: 16px;
    border-radius: 4px;
    font-weight: bold;
}

@media (min-width: 769px) {
    #message-window {
        bottom: 20px;
    }
}

/* ============================================================
   湯間庭町 layout foundation / 2026-07 organized
   ------------------------------------------------------------
   レイアウトの責任を CSS に戻すための最終上書き。

   #game-container : ブラウザ全体の舞台
   #town-screen    : 固定比率のゲーム画面
   #game-canvas    : 町の描画面。内部解像度は main.js の GAME_VIEW_W/H
   #message-window : town-screen の中に閉じ込めるセリフ枠
   ============================================================ */

:root {
    /* 論理解像度。main.js の GAME_VIEW_W/H と必ず揃える。 */
    --town-design-w: 390;
    --town-design-h: 780;
    --town-screen-max-w: 470px;
    --town-screen-ratio-w: 390;
    --town-screen-ratio-h: 780;
    --town-screen-bg: #0e1418;
    --town-page-bg-a: #1b252c;
    --town-page-bg-b: #10161b;
    --town-page-bg-c: #080b0e;
    --town-dialog-bottom: 126px;
    --town-dialog-side: 16px;
    --town-dialog-max-h: 34%;
    --town-guide-map-desktop-max-w: 620px;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 38%, var(--town-page-bg-a) 0%, var(--town-page-bg-b) 55%, var(--town-page-bg-c) 100%);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 38%, var(--town-page-bg-a) 0%, var(--town-page-bg-b) 55%, var(--town-page-bg-c) 100%);
}

#town-screen {
    position: relative;
    flex: 0 0 auto;
    width: min(
        100vw,
        calc(100dvh * var(--town-screen-ratio-w) / var(--town-screen-ratio-h)),
        var(--town-screen-max-w)
    );
    max-width: 100vw;
    aspect-ratio: var(--town-screen-ratio-w) / var(--town-screen-ratio-h);
    max-height: 100dvh;
    overflow: hidden;
    background: var(--town-screen-bg);
    box-shadow:
        0 0 0 1px rgba(255, 244, 210, 0.10),
        0 18px 50px rgba(0, 0, 0, 0.35);
    isolation: isolate;
}

#game-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* 町画面内UI。safe-area は外側の viewport ではなく、town-screen 内で扱う。 */
#town-screen #ui-layer {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 50;
}

#town-screen #area-title {
    position: absolute;
    left: 50%;
    top: 20%;
    z-index: 70;
}

#town-screen #interaction-hint {
    position: absolute;
    left: 50%;
    bottom: 146px;
    z-index: 60;
}

#town-screen #message-backdrop {
    position: absolute;
    inset: 0;
    z-index: 80;
}

#town-screen #message-window {
    position: absolute;
    left: var(--town-dialog-side);
    right: var(--town-dialog-side);
    bottom: var(--town-dialog-bottom);
    width: auto;
    max-width: none;
    max-height: var(--town-dialog-max-h);
    box-sizing: border-box;
    z-index: 90;
    overflow-y: auto;
}

/* スマホ操作UIも town-screen の中へ閉じ込める。 */
#town-screen #mobile-controls {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    height: 108px;
    padding: 0 10px;
    box-sizing: border-box;
    z-index: 80;
}

/* PCではブラウザ幅ではなく、町画面の中のUIとして扱う。 */
@media (min-width: 769px) {
    :root {
        --town-dialog-bottom: 24px;
        --town-dialog-side: 24px;
    }

    #town-screen #mobile-controls {
        display: none;
    }
}


/* スマホでは横幅優先。
   town-screen 自体を端末の表示領域いっぱいにし、
   main.js 側で canvas の内部高さだけを可変にする。
   これにより、ドット絵を横に引き伸ばさずに左右の余白を消す。 */
@media (max-width: 768px) and (pointer: coarse) {
    #game-container {
        align-items: stretch;
        justify-content: stretch;
    }

    #town-screen {
        width: 100vw;
        height: 100dvh;
        max-width: none;
        max-height: none;
        aspect-ratio: auto;
        box-shadow: none;
    }
}

@media (max-width: 390px), (max-height: 720px) {
    :root {
        --town-dialog-bottom: 120px;
        --town-dialog-side: 14px;
    }

    #town-screen #interaction-hint {
        bottom: 140px;
    }
}

/* 町外のオーバーレイ。work-player / scene-container / editor はブラウザ舞台に重ねる。 */
#scene-container,
#work-player,
#editor-panel,
#export-modal,
#btn-debug-toggle {
    position: absolute;
}

/* 駅前案内図。main.js の動的CSS生成から切り離し、ここを唯一のサイズ管理場所にする。 */
#station-guide-map-layer {
    position: fixed;
    inset: 0;
    z-index: 6500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
    box-sizing: border-box;
}

#station-guide-map-layer.visible {
    display: flex;
}

.station-guide-map-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 6, 8, 0.72);
}

.station-guide-map-window {
    position: relative;
    width: min(calc(100vw - 28px), var(--town-guide-map-desktop-max-w));
    max-height: calc(100dvh - 44px);
    border: 3px solid rgba(42, 30, 23, 0.95);
    border-radius: 14px;
    background: #2b2119;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    box-sizing: border-box;
}

.station-guide-map-image-wrap {
    position: relative;
    width: 100%;
    line-height: 0;
    background: #211811;
}

.station-guide-map-image {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-select: none;
}

.station-guide-map-hotspots {
    position: absolute;
    inset: 0;
}

.station-guide-map-hotspot {
    position: absolute;
    border: 0;
    background: rgba(255, 255, 255, 0);
    border-radius: 10px;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.18);
}

.station-guide-map-hotspot:focus-visible {
    outline: 3px solid rgba(255, 245, 180, 0.95);
    outline-offset: 2px;
    background: rgba(255, 245, 180, 0.14);
}

#station-guide-map-layer[data-debug-hotspots='true'] .station-guide-map-hotspot {
    outline: 2px dashed rgba(255, 70, 70, 0.85);
    background: rgba(255, 70, 70, 0.12);
}

.station-guide-map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    background: rgba(37, 27, 20, 0.92);
}

.station-guide-map-labels {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.station-guide-map-label {
    position: absolute;
    transform: translate(-50%, -50%);
    min-width: 54px;
    max-width: 150px;
    box-sizing: border-box;
    padding: 5px 8px 4px;
    border: 1px solid rgba(255, 239, 202, 0.78);
    border-radius: 8px;
    background: rgba(49, 34, 24, 0.84);
    color: #fff7e8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.38);
    text-align: center;
    white-space: nowrap;
    line-height: 1.12;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
}

.station-guide-map-label-main {
    display: block;
    font-size: 12px;
    font-weight: 850;
    letter-spacing: 0.02em;
}

.station-guide-map-label-sub {
    display: block;
    margin-top: 2px;
    font-size: 9px;
    font-weight: 650;
    letter-spacing: 0.05em;
    color: rgba(255, 244, 221, 0.72);
}

.station-guide-current-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border: 2px solid rgba(48, 34, 24, 0.96);
    border-radius: 50%;
    background: #fff0c2;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.48), 0 0 0 2px rgba(255, 246, 205, 0.38);
}

.station-guide-current-marker::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(49, 34, 24, 0.95);
}

.station-guide-map-close {
    position: static;
    flex: 0 0 auto;
    margin: 0;
    padding: 7px 11px;
    border: 1px solid rgba(255, 245, 220, 0.7);
    border-radius: 999px;
    background: rgba(255, 244, 223, 0.10);
    color: #fff4df;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    box-shadow: none;
}

.station-guide-map-hint {
    position: static;
    z-index: 3;
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: rgba(255, 247, 230, 0.90);
    box-shadow: none;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: 0.05em;
    text-align: left;
    white-space: nowrap;
    pointer-events: none;
}

@media (max-width: 720px) {
    .station-guide-map-window {
        width: calc(100vw - 20px);
        max-height: calc(100dvh - 20px);
        border-width: 2px;
        border-radius: 10px;
    }

    .station-guide-map-toolbar {
        padding: 7px 9px;
    }

    .station-guide-map-label {
        padding: 4px 7px 3px;
        border-radius: 7px;
    }

    .station-guide-map-label-main {
        font-size: 11px;
    }

    .station-guide-map-label-sub {
        font-size: 8px;
    }

    .station-guide-current-marker {
        width: 15px;
        height: 15px;
    }

    .station-guide-map-close {
        padding: 6px 9px;
        font-size: 11px;
    }

    .station-guide-map-hint {
        font-size: 10px;
    }
}

/* ==========================================
   湯間庭町 / 下中央の片手用コントローラー
   ========================================== */

/*
 * 左右どちらの親指でも使えるよう、操作盤を画面下中央へ置く。
 * 操作盤の外側16pxも入力保護領域とし、マップタップを通さない。
 */
#town-screen #mobile-controls {
    left: 50%;
    right: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 140px;
    height: 140px;
    padding: 16px;
    transform: translateX(-50%);
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    pointer-events: none;
}

#action-btns,
#btn-action {
    display: none !important;
    pointer-events: none !important;
}

#dpad {
    position: relative;
    flex: 0 0 auto;
    width: 108px;
    height: 108px;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    opacity: 1;
    isolation: isolate;
    pointer-events: auto;
    touch-action: none;
}

/* 十字キーの周囲もタップ移動させない安全地帯にする。 */
#dpad::before {
    content: "";
    position: absolute;
    inset: -16px;
    z-index: 0;
    background: transparent;
    pointer-events: auto;
}

#dpad:active {
    opacity: 1;
}

/* 通常時は控えめ。押している方向だけを明るくする。 */
#dpad .dpad-btn {
    z-index: 2;
    opacity: 0.52;
    transition:
        opacity 0.12s ease,
        background-color 0.12s ease,
        border-color 0.12s ease,
        color 0.12s ease,
        box-shadow 0.12s ease;
}

#dpad .dpad-btn:active,
#dpad .dpad-btn.pressed {
    opacity: 1;
    background: rgba(242, 226, 192, 0.92);
    border-color: rgba(255, 245, 218, 0.98);
    color: #29231d;
    box-shadow:
        0 0 0 2px rgba(255, 238, 200, 0.14),
        0 3px 8px rgba(0, 0, 0, 0.34);
}

/* 十字キー中央は、親指を休めるための空白として残す。
 * ボタン間の空白を押しても、マップへのタップ移動は発生しない。 */

/* 案内は操作盤のすぐ上。案内そのものも引き続きタップできる。 */
#town-screen #interaction-hint {
    bottom: 170px;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    transition:
        opacity 0.18s ease,
        transform 0.14s ease,
        background-color 0.14s ease,
        border-color 0.14s ease;
}

#interaction-hint.visible {
    pointer-events: auto;
}

#interaction-hint.hint-pressed {
    transform: translateX(-50%) translateY(2px) scale(0.985);
    background: rgba(23, 30, 40, 0.96);
    border-color: rgba(255, 240, 205, 0.78);
}

#interaction-label,
#interaction-action {
    pointer-events: none;
}

@media (max-height: 720px) {
    #town-screen #mobile-controls {
        bottom: max(8px, env(safe-area-inset-bottom));
        width: 132px;
        height: 132px;
        padding: 12px;
    }

    #dpad::before {
        inset: -12px;
    }

    #town-screen #interaction-hint {
        bottom: 154px;
    }
}

/* ==========================================
   湯間庭町 / 文字組み・改行ルール
   ========================================== */

/* エリア名は、画面右半分だけで縮まないように表示幅を明示する。 */
#town-screen #area-title {
    width: max-content;
    max-width: calc(100% - 32px);
}

#area-title-main {
    width: max-content;
    max-width: min(86vw, 340px);
    white-space: pre-line;
    word-break: keep-all;
    overflow-wrap: normal;
    text-wrap: balance;
    line-height: 1.24;
}

#area-title.multi-line #area-title-main {
    font-size: 22px;
    line-height: 1.28;
}

#area-title-sub {
    max-width: min(86vw, 340px);
    text-wrap: balance;
    line-height: 1.35;
}

/* 操作案内はボタンとして一行を維持する。 */
#town-screen #interaction-hint {
    box-sizing: border-box;
    width: max-content;
    max-width: calc(100% - 28px);
    flex-wrap: nowrap;
    justify-content: center;
    white-space: nowrap;
}

#interaction-label {
    min-width: 0;
    flex: 0 1 auto;
    white-space: nowrap;
    word-break: keep-all;
    overflow-wrap: normal;
}

#interaction-action {
    flex: 0 0 auto;
    white-space: nowrap;
    word-break: keep-all;
}

/* 長い施設名だけ、実測結果に応じて一段ずつ小さくする。 */
#interaction-hint.hint-compact {
    gap: 8px;
    padding-left: 12px;
    padding-right: 12px;
}

#interaction-hint.hint-compact #interaction-label {
    font-size: 13px;
    letter-spacing: 0;
}

#interaction-hint.hint-compact #interaction-action {
    font-size: 11px;
    padding-left: 7px;
    padding-right: 7px;
}

#interaction-hint.hint-tight {
    gap: 6px;
    padding-left: 9px;
    padding-right: 9px;
}

#interaction-hint.hint-tight #interaction-label {
    font-size: 12px;
}

#interaction-hint.hint-tight #interaction-action {
    font-size: 10px;
    padding-left: 6px;
    padding-right: 6px;
}

/* Wide Editor workspace: 470px town + 284px inspector + 16px gap.
   Keep short landscape viewports on the base overlay layout. */
@media (min-width: 820px) and (min-height: 600px) {
    #editor-panel {
        position: relative;
        top: auto;
        right: auto;
        flex: 0 0 auto;
        margin-left: 16px;
    }
}


/* 町内記事も既存noteカードと同じ外形にし、薄い紙色で区別する。 */
.shinpo-archive-card { background: #f4f0e6; }
.shinpo-archive-paper {
    color: #352e25;
    padding: 16px;
    box-sizing: border-box;
    font-family: system-ui, sans-serif;
}
.shinpo-archive-mast {
    color: #6b6255;
    font-size: 11px;
    line-height: 1.5;
}
.shinpo-archive-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
.shinpo-archive-date { color: #6b6255; font-size: 11px; line-height: 1.5; }
.shinpo-archive-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.shinpo-archive-content.has-thumbnail { grid-template-columns: minmax(0, 1fr) 28%; }
.shinpo-archive-thumbnail { display: block; width: 100%; height: auto; aspect-ratio: 1280 / 670; object-fit: contain; }
.shinpo-archive-headline {
    font-size: 19px;
    font-weight: 700;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.shinpo-archive-card .note-rack-card-open:focus-visible {
    outline-color: #51463a;
}
