/* My Town — play/style.css + level-editor tile-palette üzerine ince override */

body.mytown-page,
body.mytown-view {
    --mytown-scene-bg: url('../assets/images/towns.png');
    --mytown-bg-size: cover;
    --mytown-bg-repeat: no-repeat;
}

body.mytown-page {
    --p-topbar-h: 62px;
    background:
        radial-gradient(circle at top left, rgba(111, 127, 153, 0.12), transparent 32rem),
        radial-gradient(circle at 88% 12%, rgba(155, 185, 207, 0.14), transparent 28rem),
        linear-gradient(180deg, rgba(251, 253, 255, 0.78) 0%, rgba(243, 247, 251, 0.84) 50%, rgba(248, 250, 252, 0.86) 100%),
        var(--mytown-scene-bg) center center / var(--mytown-bg-size, cover) var(--mytown-bg-repeat, no-repeat) fixed !important;
    overflow: hidden;
}

.mytown-page-loading {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: grid;
    place-items: center;
    background:
        linear-gradient(180deg, rgba(251, 253, 255, 0.88) 0%, rgba(243, 247, 251, 0.92) 100%),
        var(--mytown-scene-bg, none) center center / var(--mytown-bg-size, cover) var(--mytown-bg-repeat, no-repeat);
    transition: opacity 0.28s ease, visibility 0.28s ease;
}

.mytown-page-loading.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Lazy tile / nesne yükleme */
#mytownBoard.mytown-board--building {
    opacity: 0.94;
}

#mytownBoard .cell-tile.mytown-lazy-pending,
#mytownBoard .cell-object.mytown-lazy-pending,
.tile-palette__item img.mytown-lazy-pending {
    background: rgba(116, 185, 77, 0.32);
}

#mytownBoard .mytown-lazy-loaded,
.tile-palette__item img.mytown-lazy-loaded {
    transition: opacity 0.18s ease;
}

.mytown-page-loading__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    min-width: 220px;
    padding: 24px 28px;
    border-radius: 20px;
    border: 2px solid var(--game-frame-dark, #2d1a0c);
    background: linear-gradient(180deg, rgba(255, 249, 235, 0.96) 0%, rgba(243, 230, 200, 0.96) 100%);
    box-shadow:
        0 4px 0 var(--game-frame-dark, #2d1a0c),
        0 18px 40px rgba(45, 26, 12, 0.18);
    color: #3d2914;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
}

.mytown-page-loading__spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid rgba(45, 26, 12, 0.14);
    border-top-color: var(--game-green, #5fa56b);
    animation: mytown-page-loading-spin 0.8s linear infinite;
}

.mytown-page-loading__card p {
    margin: 0;
}

@keyframes mytown-page-loading-spin {
    to { transform: rotate(360deg); }
}

/* ========== Üst çubuk — play-site-brand / game-brand-mark beige dili ========== */
.mytown-header {
    position: fixed;
    top: 10px;
    left: 50%;
    z-index: var(--z-play-level-nav, 120);
    transform: translateX(-50%);
    width: max-content;
    max-width: min(calc(100vw - 20px), 760px);
    pointer-events: none;
}

.mytown-header__bar {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px 5px 5px;
    border: 2px solid var(--game-frame-dark, #2d1a0c);
    border-radius: 12px;
    background: linear-gradient(180deg, var(--game-paper, #fff9eb) 0%, var(--game-paper-deep, #f3e6c8) 100%);
    box-shadow:
        0 2px 0 var(--game-frame-dark, #2d1a0c),
        0 4px 12px rgba(45, 26, 12, 0.12);
}

.mytown-header__nav,
.mytown-header__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.mytown-header__btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    border-radius: 10px !important;
    border: 2px solid var(--game-frame-dark, #2d1a0c) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    cursor: pointer !important;
    color: #4e342e !important;
    background: linear-gradient(165deg, #f8f0dc 0%, #e6d4b0 100%) !important;
    box-shadow:
        0 2px 0 var(--game-frame-dark, #2d1a0c),
        inset 0 1px 0 rgba(255, 255, 255, 0.55) !important;
    transition: transform 0.18s ease, filter 0.18s ease, background 0.18s ease !important;
}

.mytown-header__btn i {
    font-size: 0.95rem !important;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.35));
}

.mytown-header__btn:hover {
    transform: translateY(-1px) !important;
    filter: brightness(1.04) !important;
}

.mytown-header__btn:active {
    transform: translateY(1px) !important;
    box-shadow:
        0 1px 0 var(--game-frame-dark, #2d1a0c),
        inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
}

.mytown-header__btn--share {
    background: linear-gradient(145deg, var(--game-green, #5fa56b), var(--game-green-dark, #3f7a48)) !important;
    color: #fff !important;
    border-color: var(--game-frame-dark, #2d1a0c) !important;
}

.mytown-view-like {
    width: auto !important;
    min-width: 36px !important;
    padding: 0 10px !important;
    gap: 6px;
}

.mytown-view-like.is-liked {
    color: #dc2626 !important;
    background: linear-gradient(165deg, #ffe4e6 0%, #fecdd3 100%) !important;
}

.mytown-view-like__count {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
}

.mytown-header__btn--share:hover {
    filter: brightness(1.06) !important;
}

.mytown-header__btn--clear:hover {
    background: linear-gradient(165deg, #fecaca 0%, #fca5a5 100%) !important;
    color: #7f1d1d !important;
}

.mytown-header__main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    padding: 0 2px;
}

.mytown-header__teacher-tag {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-family: var(--font-game, "Fredoka", "Quicksand", sans-serif);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(145deg, var(--game-gold, #f1b04a), var(--game-gold-dark, #c98a1f));
    border: 1.5px solid var(--game-frame-dark, #2d1a0c);
    box-shadow: 0 1px 0 var(--game-frame-dark, #2d1a0c);
}

.mytown-header__name-wrap {
    display: flex;
    min-width: 0;
    margin: 0;
}

.mytown-header__name {
    width: min(220px, 40vw);
    min-width: 120px;
    padding: 6px 12px;
    border: 2px solid rgba(45, 26, 12, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--game-code-ink, #5d4037);
    font-family: var(--font-game, "Fredoka", "Quicksand", sans-serif);
    font-weight: 800;
    font-size: 0.88rem;
    text-align: center;
    box-shadow: inset 0 1px 2px rgba(45, 26, 12, 0.05);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.mytown-header__name::placeholder {
    color: rgba(93, 64, 55, 0.42);
    font-weight: 700;
}

.mytown-header__name:focus {
    outline: none;
    border-color: var(--game-green, #5fa56b);
    box-shadow: 0 0 0 3px rgba(95, 165, 107, 0.22);
}

.mytown-header__save {
    flex-shrink: 0;
    font-family: var(--font-game, "Fredoka", "Quicksand", sans-serif);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8b7355;
    white-space: nowrap;
}

.mytown-header__save.is-saved {
    color: var(--game-green-dark, #3f7a48);
}

.mytown-header__main--view {
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 2px 10px;
}

.mytown-header__title {
    font-family: var(--font-game, "Fredoka", "Quicksand", sans-serif);
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--game-code-ink, #5d4037);
    line-height: 1.2;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.mytown-header__author {
    font-size: 0.68rem;
    font-weight: 700;
    color: #8b7355;
    line-height: 1.2;
}

/* Sol panel — oyun code-panel genişliği */
body.mytown-page .code-panel {
    --p-code-column: 320px;
    width: calc(var(--p-palette-rail) + var(--p-code-column) + 12px) !important;
    min-width: calc(var(--p-palette-rail) + var(--p-code-column) + 12px) !important;
    max-width: calc(var(--p-palette-rail) + var(--p-code-column) + 12px) !important;
}

/* Sol ray — envanter/zemin: play .palette-view-controls .control-button ile aynı dil */
.mytown-rail {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.mytown-rail .palette-view-controls--tabs {
    margin-top: 0 !important;
    flex-shrink: 0;
    padding-top: 8px !important;
}

.mytown-rail-tools {
    margin-top: 0 !important;
    flex-shrink: 0;
    padding-top: 8px !important;
}

.mytown-rail > .palette-view-controls:last-child {
    margin-top: auto !important;
}

.code-panel .mytown-rail .mytown-tab-btn:hover {
    transform: translateY(-1px) !important;
    filter: brightness(1.04) !important;
}

.code-panel .mytown-rail .mytown-tab-btn:active {
    transform: translateY(2px) !important;
    box-shadow:
        0 1px 0 var(--game-frame-dark),
        inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
}

.code-panel .mytown-rail .mytown-tab-btn[data-tab="inventory"].active {
    background: linear-gradient(145deg, #fbbf24, #d97706) !important;
    color: #fff !important;
    border-color: #92400e !important;
    box-shadow:
        0 3px 0 #92400e,
        inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

.code-panel .mytown-rail .mytown-tab-btn[data-tab="ground"].active {
    background: linear-gradient(145deg, #5fcf80, #34b364) !important;
    color: #fff !important;
    border-color: #166534 !important;
    box-shadow:
        0 3px 0 #166534,
        inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

/* Sol ray araç düğmeleri — varsayılan beige; seçiliyken kendi rengi */
.mytown-rail-tools .mytown-tool-btn--place.is-active {
    background: linear-gradient(145deg, #ffe082 0%, #f1c40f 45%, #f39c12 100%) !important;
    color: #fff !important;
    border-color: var(--game-frame-dark) !important;
}

.mytown-rail-tools .mytown-tool-btn--move.is-active {
    background: linear-gradient(145deg, #34d9c8, #0d9488) !important;
    color: #fff !important;
    border-color: #115e59 !important;
    box-shadow: 0 3px 0 #115e59, inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

.mytown-rail-tools .mytown-tool-btn--delete.is-active {
    background: linear-gradient(145deg, #fca5a5, #ef4444) !important;
    color: #fff !important;
    border-color: #991b1b !important;
    box-shadow: 0 3px 0 #991b1b, inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

.mytown-rail-tools .mytown-tool-btn--grow.is-active {
    background: linear-gradient(145deg, #c4b5fd, #7c3aed) !important;
    color: #fff !important;
    border-color: #5b21b6 !important;
    box-shadow: 0 3px 0 #5b21b6, inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

.mytown-rail-tools .mytown-tool-btn--shrink.is-active {
    background: linear-gradient(145deg, #fdba74, #ea580c) !important;
    color: #fff !important;
    border-color: #9a3412 !important;
    box-shadow: 0 3px 0 #9a3412, inset 0 1px 0 rgba(255, 255, 255, 0.35) !important;
}

.mytown-rail-tools .mytown-tool-btn.is-active {
    box-shadow:
        0 0 0 3px rgba(255, 213, 79, 0.55),
        0 3px 0 var(--game-frame-dark),
        inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
    transform: translateY(-1px);
}

.mytown-rail-tools .mytown-tool-btn:hover {
    transform: translateY(-1px) !important;
    filter: brightness(1.04) !important;
}

.mytown-rail-tools .mytown-tool-btn:active {
    transform: translateY(2px) !important;
}

.mytown-palette-section {
    min-width: 0;
}

.mytown-palette-section .code-container-dis {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 8px 10px 0 !important;
}

.mytown-scroll-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mytown-tabpanel {
    display: none;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.mytown-tabpanel.is-active {
    display: flex;
}

/* Panel içeriği — sol sekme seçiliyken düz ızgara, iç kategori yok */
.mytown-panel-area {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.mytown-panel-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 8px 12px;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 14px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.mytown-panel-grid .tile-palette__category.mytown-palette__category {
    margin-bottom: 12px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.mytown-palette__title {
    margin: 0 0 6px;
    padding: 0 2px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
    line-height: 1.3;
}

.mytown-panel-grid .tile-palette__grid,
.mytown-panel-grid .tile-palette__grid.tile-palette__grid--props {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    max-height: none;
    overflow: visible;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
}

.mytown-panel-grid .tile-palette__loading {
    padding: 24px 12px;
    text-align: center;
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 600;
}

.mytown-panel-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px 18px;
    text-align: center;
    background: rgba(255, 255, 255, 0.88);
    border-radius: 14px;
    border: 2px dashed rgba(45, 26, 12, 0.12);
}

.mytown-panel-empty[hidden] {
    display: none !important;
}

.mytown-panel-empty__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(165deg, #f8f0dc 0%, #e6d4b0 100%);
    color: #4e342e;
    border: 3px solid var(--game-frame-dark, #2d1a0c);
    box-shadow: 0 3px 0 var(--game-frame-dark, #2d1a0c), inset 0 1px 0 rgba(255, 255, 255, 0.55);
    font-size: 1.2rem;
}

.mytown-panel-empty p {
    margin: 0;
    max-width: 220px;
    font-size: 0.82rem;
    line-height: 1.45;
    color: #64748b;
    font-weight: 600;
}

.mytown-panel-empty__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 12px;
    background: linear-gradient(145deg, #5fcf80, #34b364);
    color: #fff;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 700;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.mytown-panel-empty__link:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.mytown-panel-grid .tile-palette__item {
    appearance: none;
    font-family: inherit;
}

.mytown-panel-grid .tile-palette__item--prop {
    position: relative;
}

.mytown-panel-grid .tile-palette__item .mytown-inv-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: linear-gradient(160deg, #34d399, #059669);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    border: 2px solid #fff;
    z-index: 2;
    pointer-events: none;
}

.mytown-empty {
    text-align: center;
    padding: 24px 14px;
    color: #64748b;
}

.mytown-empty i {
    font-size: 2rem;
    color: #cbd5e1;
    margin-bottom: 10px;
}

.mytown-empty p {
    font-size: 0.85rem;
    line-height: 1.4;
    margin: 0 0 12px;
}

.mytown-empty__btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 999px;
    background: #22c55e;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.85rem;
}

/* Izgara etkileşim — ::after üst katmanda (sunucuda eski JS olsa da is-occupied ile çalışır) */
#mytownBoard .cell::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 30 !important;
    pointer-events: none;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.12s ease;
}

body.mytown-item-place-mode #mytownBoard .cell.is-occupied::after {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.45) !important;
}

#mytownBoard .cell.is-drop-target::after {
    opacity: 1 !important;
    background: rgba(34, 197, 94, 0.4) !important;
}

#mytownBoard .cell.is-pickup::after {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.58) !important;
}

/* JS overlay div — yedek (paintCellOverlay) */
#mytownBoard .cell-slot-overlay {
    position: absolute !important;
    inset: 0 !important;
    z-index: 31 !important;
    pointer-events: none !important;
    box-sizing: border-box !important;
    opacity: 0;
    transition: opacity 0.12s ease;
}

body.mytown-item-place-mode #mytownBoard .cell.is-occupied .cell-slot-overlay {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.45) !important;
}

#mytownBoard .cell.is-drop-target .cell-slot-overlay {
    opacity: 1 !important;
    background: rgba(34, 197, 94, 0.4) !important;
}

#mytownBoard .cell.is-pickup .cell-slot-overlay {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.58) !important;
}

body.mytown-tool-delete #mytownBoard .cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(239, 68, 68, 0.2);
}

body.mytown-tool-move #mytownBoard .cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(59, 130, 246, 0.16);
}

body.mytown-tool-grow #mytownBoard .cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(124, 58, 237, 0.18);
}

body.mytown-tool-shrink #mytownBoard .cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(234, 88, 12, 0.16);
}

#mytownBoard .cell {
    overflow: visible;
}

#mytownBoard .cell-obstacle-wrap--2x2 {
    width: 200%;
    height: 200%;
    z-index: 4;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 4%;
}

#mytownBoard .cell-obstacle-wrap--2x2 .cell-object {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: left bottom;
}

#mytownBoard .cell-obstacle-wrap--3x3 {
    width: 300%;
    height: 300%;
    z-index: 5;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 3%;
}

#mytownBoard .cell-obstacle-wrap--3x3 .cell-object {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: left bottom;
}

.mytown-view-board .cell-obstacle-wrap--2x2,
.mytown-view-board .cell-obstacle-wrap--3x3 {
    width: 200%;
    height: 200%;
    z-index: 4;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 4%;
}

.mytown-view-board .cell-obstacle-wrap--3x3 {
    width: 300%;
    height: 300%;
    z-index: 5;
    padding: 3%;
}

.mytown-view-board .cell-obstacle-wrap--2x2 .cell-object,
.mytown-view-board .cell-obstacle-wrap--3x3 .cell-object {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: left bottom;
}

/* Sürükleme hayaleti */
.mytown-drag-ghost {
    position: fixed;
    z-index: 9999;
    width: 64px;
    height: 64px;
    pointer-events: none;
    transform: translate(-50%, -50%);
    opacity: 0.92;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
}

.mytown-drag-ghost img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ========== Görüntüleme sayfası ========== */
body.mytown-view {
    background:
        linear-gradient(180deg, rgba(251, 253, 255, 0.74) 0%, rgba(243, 247, 251, 0.82) 100%),
        var(--mytown-scene-bg) center center / var(--mytown-bg-size, cover) var(--mytown-bg-repeat, no-repeat) fixed !important;
    overflow: hidden;
}

.mytown-view-layout {
    grid-template-columns: 1fr !important;
    grid-template-areas: "game" !important;
}

.mytown-view-layout .game-area {
    width: 100%;
}

.mytown-empty--view {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 18px;
    padding: 48px 32px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    max-width: 420px;
}

.mytown-empty--view h2 {
    margin: 0 0 8px;
    color: #0f172a;
}

/* Paylaşım modalı — oyun/beige kart stili */
.mytown-modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.mytown-modal[hidden] {
    display: none;
}

.mytown-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(45, 26, 12, 0.45);
    backdrop-filter: blur(4px);
}

.mytown-modal__dialog {
    position: relative;
    width: min(460px, 100%);
    max-height: min(92vh, 640px);
    overflow: auto;
    padding: 28px 24px 22px;
    border: 3px solid var(--game-frame-dark, #2d1a0c);
    border-radius: 22px;
    background:
        radial-gradient(circle at 16% 8%, rgba(241, 176, 74, 0.2), transparent 42%),
        radial-gradient(circle at 88% 10%, rgba(95, 165, 107, 0.16), transparent 38%),
        linear-gradient(180deg, var(--game-paper, #fff9eb) 0%, var(--game-paper-deep, #f3e6c8) 100%);
    box-shadow:
        0 6px 0 var(--game-frame-dark, #2d1a0c),
        0 22px 48px rgba(45, 26, 12, 0.28);
}

.mytown-modal__sparkles {
    pointer-events: none;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    overflow: hidden;
}

.mytown-modal__sparkles::before,
.mytown-modal__sparkles::after {
    content: '';
    position: absolute;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    opacity: 0.35;
}

.mytown-modal__sparkles::before {
    top: -28px;
    left: -18px;
    background: radial-gradient(circle, rgba(95, 165, 107, 0.55), transparent 68%);
}

.mytown-modal__sparkles::after {
    top: -20px;
    right: -24px;
    background: radial-gradient(circle, rgba(241, 176, 74, 0.5), transparent 68%);
}

.mytown-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 2px solid var(--game-frame-dark, #2d1a0c);
    border-radius: 10px;
    background: linear-gradient(165deg, #f8f0dc 0%, #e6d4b0 100%);
    color: #4e342e;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 0 var(--game-frame-dark, #2d1a0c);
}

.mytown-modal__head {
    position: relative;
    text-align: center;
    margin-bottom: 18px;
    padding-top: 4px;
}

.mytown-modal__kicker {
    display: inline-flex;
    align-items: center;
    margin-bottom: 10px;
    padding: 3px 10px;
    border-radius: 999px;
    font-family: 'Fredoka', 'Space Grotesk', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(145deg, #5fa56b, #3f7a48);
    border: 1.5px solid var(--game-frame-dark, #2d1a0c);
    box-shadow: 0 1px 0 var(--game-frame-dark, #2d1a0c);
}

.mytown-modal__icon {
    display: inline-flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    border: 2px solid var(--game-frame-dark, #2d1a0c);
    background: linear-gradient(145deg, #f1b04a, #c98a1f);
    color: #fff;
    font-size: 1.35rem;
    margin-bottom: 12px;
    box-shadow: 0 3px 0 var(--game-frame-dark, #2d1a0c);
}

.mytown-modal__head h2 {
    margin: 0 0 8px;
    font-family: 'Fredoka', 'Space Grotesk', sans-serif;
    font-size: 1.45rem;
    font-weight: 700;
    color: #3d2914;
    letter-spacing: -0.02em;
}

.mytown-modal__head p {
    margin: 0;
    color: #6b5344;
    font-size: 0.92rem;
    line-height: 1.5;
    max-width: 34ch;
    margin-left: auto;
    margin-right: auto;
}

.mytown-modal__panel {
    border: 2px solid rgba(45, 26, 12, 0.12);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.42);
    padding: 16px;
}

.mytown-field {
    display: block;
    margin-bottom: 14px;
}

.mytown-field:last-of-type {
    margin-bottom: 0;
}

.mytown-field span {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    font-size: 0.82rem;
    color: #4e342e;
}

.mytown-field input {
    width: 100%;
    padding: 11px 13px;
    border: 2px solid rgba(45, 26, 12, 0.16);
    border-radius: 12px;
    font: inherit;
    color: #3d2914;
    background: rgba(255, 249, 235, 0.92);
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mytown-field input:focus {
    outline: none;
    border-color: #5fa56b;
    box-shadow: 0 0 0 3px rgba(95, 165, 107, 0.22);
}

.mytown-modal__message {
    padding: 10px 13px;
    border-radius: 12px;
    font-size: 0.85rem;
    margin-top: 12px;
    border: 1.5px solid transparent;
}

.mytown-modal__message--error {
    background: #fde8e8;
    color: #9f1239;
    border-color: rgba(159, 18, 57, 0.18);
}

.mytown-modal__message--info {
    background: #e8f4ff;
    color: #0c4a6e;
    border-color: rgba(12, 74, 110, 0.16);
}

.mytown-share-result {
    margin-top: 12px;
    padding: 14px;
    border-radius: 14px;
    background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%);
    border: 2px solid rgba(45, 26, 12, 0.14);
    text-align: center;
}

.mytown-share-result__title {
    margin: 0 0 10px;
    font-weight: 700;
    color: #065f46;
    font-size: 0.92rem;
}

.mytown-share-result__link {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    border: 1.5px dashed rgba(45, 26, 12, 0.18);
    color: #15803d;
    font-weight: 700;
    font-size: 0.82rem;
    word-break: break-all;
    text-decoration: none;
}

.mytown-share-result__link:hover {
    color: #166534;
    background: rgba(255, 255, 255, 0.92);
}

.mytown-modal__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.mytown-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border: 2px solid var(--game-frame-dark, #2d1a0c);
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 0 var(--game-frame-dark, #2d1a0c);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.mytown-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

.mytown-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 var(--game-frame-dark, #2d1a0c);
}

.mytown-btn--ghost {
    background: linear-gradient(165deg, #f8f0dc 0%, #e6d4b0 100%);
    color: #4e342e;
}

.mytown-btn--primary {
    background: linear-gradient(145deg, #5fa56b, #3f7a48);
    color: #fff;
}

@media (max-width: 1024px) {
    body.mytown-page.play-mobile-drawer {
        overflow: hidden !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
    }

    body.mytown-page.play-mobile-drawer .code-panel {
        --p-code-column: min(58vw, 300px);
    }

    body.mytown-page.play-mobile-drawer .mytown-header {
        max-width: calc(100vw - 12px);
    }

    body.mytown-page.play-mobile-drawer .mytown-header__name {
        width: min(160px, 36vw);
        min-width: 100px;
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    body.mytown-page.play-mobile-drawer .mytown-header__save {
        display: none;
    }
}

@media (max-width: 900px) {
    body.mytown-page:not(.play-mobile-drawer) {
        overflow: auto;
        --p-topbar-h: 58px;
    }

    body.mytown-page:not(.play-mobile-drawer) .code-panel {
        --p-code-column: 260px;
    }
}
