:root {
    --ink: #24483d;
    --ink-soft: #587169;
    --cream: #fffaf0;
    --cream-solid: #fffdf8;
    --line: rgba(56, 91, 79, 0.14);
    --leaf: #4f9a72;
    --leaf-dark: #36785a;
    --leaf-soft: #dff1df;
    --peach: #f39a69;
    --coral: #e96f73;
    --sky: #8dd3e8;
    --blue: #6aaeda;
    --gold: #f3b94e;
    --danger: #b85e5e;
    --shadow-sm: 0 6px 18px rgba(35, 73, 61, 0.13);
    --shadow-lg: 0 22px 55px rgba(28, 65, 54, 0.2);
    --radius-sm: 15px;
    --radius-md: 22px;
    --radius-lg: 32px;
    --font-ui: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    --font-display: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
    --safe-top: max(12px, env(safe-area-inset-top));
    --safe-right: max(12px, env(safe-area-inset-right));
    --safe-bottom: max(12px, env(safe-area-inset-bottom));
    --safe-left: max(12px, env(safe-area-inset-left));
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: #dff4ee;
    color: var(--ink);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    touch-action: none;
}

body::before, body::after { display: none !important; }

button, input, output { font: inherit; }

button {
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
.file-button:focus-within {
    outline: 3px solid rgba(38, 112, 85, 0.45);
    outline-offset: 3px;
}

button:disabled { opacity: .46; cursor: not-allowed; transform: none !important; }

.hidden { display: none !important; }
.mobile-only { display: none !important; }
.svg-defs { position: fixed; width: 0; height: 0; overflow: hidden; }

#game-wrapper {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    isolation: isolate;
    background: linear-gradient(#8fd4ea 0%, #c9ebee 60%, #ecf7e9 100%);
}

#gameCanvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

#gameCanvas.dragging { cursor: grabbing; }
#gameCanvas.piti-hover { cursor: pointer; }
#gameCanvas.decorating { cursor: crosshair; }

.topbar {
    position: absolute;
    z-index: 30;
    top: var(--safe-top);
    left: var(--safe-left);
    right: var(--safe-right);
    display: flex;
    align-items: flex-start;
    pointer-events: none;
}

.brand-lockup {
    position: relative;
    min-width: 178px;
    padding: 9px 24px 12px 23px;
    border: 1px solid rgba(90, 107, 76, .13);
    border-radius: 30px 32px 34px 27px;
    background: rgba(255, 250, 240, .96);
    box-shadow: var(--shadow-sm);
    transform: rotate(-1deg);
    color: #7a3f31;
    font-family: var(--font-display);
    line-height: .86;
    pointer-events: auto;
}

.brand-lockup::before,
.brand-lockup::after {
    content: "";
    position: absolute;
    z-index: -1;
    border-radius: 50%;
    background: inherit;
}

.brand-lockup::before { width: 46px; height: 46px; left: -6px; top: 12px; }
.brand-lockup::after { width: 54px; height: 50px; right: -6px; bottom: 5px; }
.brand-lockup span { display: block; }
.brand-line { font-size: 22px; letter-spacing: -.7px; }
.brand-world { position: relative; margin-top: 5px; color: #285e51; font-size: 31px; letter-spacing: -1.5px; }

.brand-world i {
    position: absolute;
    width: 14px;
    height: 9px;
    top: -3px;
    right: 12px;
    border-radius: 100% 0 100% 0;
    background: #70aa70;
    transform: rotate(-25deg);
}

.world-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 5px 0 0 12px;
    padding: 9px 16px 9px 12px;
    min-width: 142px;
    border: 1px solid rgba(74, 105, 90, .12);
    border-radius: 22px;
    background: rgba(255, 250, 240, .92);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    pointer-events: auto;
}

.weather-icon { font-size: 25px; filter: drop-shadow(0 2px 2px rgba(54, 81, 69, .12)); }
.world-status strong, .world-status small { display: block; white-space: nowrap; }
.world-status strong { font-size: 14px; letter-spacing: .01em; }
.world-status small { margin-top: 2px; color: var(--ink-soft); font-size: 11px; }

.top-actions {
    display: flex;
    gap: 9px;
    margin-left: auto;
    pointer-events: auto;
}

.icon-button,
.small-icon-button {
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(62, 91, 80, .14);
    border-radius: 50%;
    background: rgba(255, 250, 240, .95);
    color: #355f53;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}

.icon-button { width: 48px; height: 48px; }
.icon-button svg { width: 23px; height: 23px; }
.small-icon-button { width: 40px; height: 40px; }
.small-icon-button svg { width: 19px; height: 19px; }

@media (hover:hover) {
    .icon-button:hover, .small-icon-button:hover { transform: translateY(-2px); background: #fff; box-shadow: 0 10px 25px rgba(35,73,61,.18); }
}

.preview-badge {
    position: absolute;
    z-index: 40;
    top: calc(var(--safe-top) + 91px);
    left: calc(var(--safe-left) + 9px);
    padding: 5px 10px;
    border-radius: 9px;
    background: #744a2b;
    color: #fff9e9;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    box-shadow: var(--shadow-sm);
}

.hud-panel {
    position: absolute;
    z-index: 24;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 250, 240, .94);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}

.journal-panel {
    top: 142px;
    left: var(--safe-left);
    width: 244px;
    padding: 17px;
}

.request-card {
    top: 88px;
    right: var(--safe-right);
    width: 238px;
    padding: 16px 17px;
}

.panel-heading, .panel-heading > div {
    display: flex;
    align-items: center;
    gap: 9px;
}

.panel-heading { justify-content: space-between; }
.panel-heading h2 { margin: 0; font-family: var(--font-display); font-size: 16px; letter-spacing: -.2px; }
.panel-icon { font-size: 18px; }
.panel-close { border: 0; background: transparent; font-size: 26px; cursor: pointer; }

.story-list { display: grid; gap: 0; margin-top: 9px; }

.event-item {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 9px;
    min-height: 54px;
    padding: 10px 0;
    border-top: 1px solid rgba(62, 91, 80, .1);
    color: var(--ink-soft);
    font-size: 12px;
    line-height: 1.35;
}

.event-item:first-child { border-top: 0; }
.event-emoji { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 12px; background: var(--leaf-soft); font-size: 17px; }
.event-copy strong { display: block; margin-bottom: 2px; color: var(--ink); font-size: 12px; }
.event-copy small { display: block; margin-top: 3px; color: #8a9b95; font-size: 10px; }

.text-button {
    width: 100%;
    margin-top: 5px;
    padding: 8px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--leaf-dark);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.text-button:hover { background: rgba(79,154,114,.09); }

.request-card p { min-height: 34px; margin: 12px 0 10px; color: var(--ink-soft); font-size: 12px; line-height: 1.4; }
.request-progress { height: 7px; overflow: hidden; border-radius: 10px; background: #dfe3dc; }
.request-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #5f9e6f, #82bc79); transition: width .35s ease; }
.request-meta { display: flex; justify-content: space-between; margin-top: 7px; color: #70837c; font-size: 11px; }
.request-meta strong { color: #b17819; }

.camera-tools {
    position: absolute;
    z-index: 23;
    top: 48%;
    right: var(--safe-right);
    display: grid;
    gap: 7px;
    transform: translateY(-50%);
}

.piti-dock {
    position: absolute;
    z-index: 32;
    left: 50%;
    bottom: max(17px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 142px minmax(260px, 330px) minmax(330px, 440px);
    align-items: center;
    gap: 17px;
    width: min(980px, calc(100vw - 420px));
    min-height: 158px;
    padding: 15px 19px 15px 14px;
    border: 1px solid rgba(79, 94, 72, .15);
    border-radius: 38px;
    background: rgba(255, 250, 240, .97);
    box-shadow: var(--shadow-lg);
    transform: translateX(-50%);
    backdrop-filter: blur(15px);
}

.dock-close {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 2;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #71827c;
    font-size: 23px;
    cursor: pointer;
}

.portrait-wrap {
    position: relative;
    display: grid;
    place-items: center;
    width: 132px;
    height: 132px;
    overflow: hidden;
    border: 6px solid #fffdf7;
    border-radius: 50%;
    background: linear-gradient(145deg, #cfe9f1, #e9f2d7);
    box-shadow: inset 0 0 0 1px rgba(58, 100, 83, .12), 0 8px 20px rgba(45, 76, 65, .13);
}

#piti-portrait { width: 132px; height: 132px; }
.portrait-mood { position: absolute; right: 4px; bottom: 3px; display: grid; place-items: center; width: 34px; height: 34px; border: 3px solid var(--cream); border-radius: 50%; background: #fff; font-size: 17px; box-shadow: var(--shadow-sm); }

.piti-summary { min-width: 0; padding-right: 4px; }
.piti-name-row { display: grid; grid-template-columns: 28px minmax(0,1fr) 28px; align-items: center; gap: 7px; text-align: center; }
.piti-name-row h2 { overflow: hidden; margin: 0; color: #1f4539; font-family: var(--font-display); font-size: 22px; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.piti-name-row p { overflow: hidden; margin: 4px 0 0; color: var(--ink-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.mini-nav { width: 28px; height: 32px; padding: 0; border: 0; border-radius: 10px; background: rgba(79,154,114,.09); color: var(--leaf-dark); font-size: 24px; cursor: pointer; }

.trait-list { display: flex; justify-content: center; gap: 5px; margin-top: 7px; min-height: 20px; }
.trait-badge { padding: 3px 8px; border-radius: 9px; background: #edf4e6; color: #526e62; font-size: 9px; font-weight: 800; }

.needs-compact { display: grid; gap: 5px; margin-top: 9px; }
.needs-compact > div { display: grid; grid-template-columns: 46px minmax(60px,1fr) 31px; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 9px; }
.needs-compact i { height: 6px; overflow: hidden; border-radius: 9px; background: #dfe5de; }
.needs-compact b { display: block; width: 50%; height: 100%; border-radius: inherit; background: var(--leaf); transition: width .35s ease, background .35s ease; }
.needs-compact output { text-align: right; font-size: 9px; }

.piti-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(58px, 1fr));
    gap: 8px;
    padding-left: 16px;
    border-left: 1px solid rgba(53, 89, 75, .12);
}

.piti-actions button {
    display: grid;
    justify-items: center;
    gap: 7px;
    min-height: 79px;
    padding: 9px 5px;
    border: 0;
    border-radius: 18px;
    background: #ecf2dd;
    color: #355e50;
    font-size: 9px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .16s ease, filter .16s ease;
}

.piti-actions button:nth-child(1) { background: #fbd7ad; color: #9a5529; }
.piti-actions button:nth-child(2) { background: #badcf3; color: #366b92; }
.piti-actions button:nth-child(3) { background: #f5bdc1; color: #9e4650; }
.piti-actions button:nth-child(4) { background: #bdddbf; color: #376b4b; }
.piti-actions button:nth-child(5) { background: #e2d3ef; color: #685283; }
.piti-actions button > span:first-child { display: grid; place-items: center; min-height: 31px; font-family: var(--font-display); font-size: 27px; line-height: 1; }
.piti-actions button:nth-child(5) > span:first-child { font-size: 11px; letter-spacing: 1px; }

@media (hover:hover) { .piti-actions button:hover { transform: translateY(-3px); filter: saturate(1.08); } }

.choice-tray {
    position: absolute;
    z-index: 45;
    left: 50%;
    bottom: 215px;
    width: min(430px, calc(100vw - 28px));
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(255,253,248,.98);
    box-shadow: var(--shadow-lg);
    transform: translateX(-50%);
}

.choice-tray-title { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 8px; font-size: 13px; }
.choice-tray-title button { border: 0; background: none; color: var(--ink-soft); font-size: 22px; cursor: pointer; }
.choice-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.choice-options button { min-height: 64px; padding: 6px 3px; border: 1px solid rgba(50,88,74,.08); border-radius: 15px; background: #f7f1df; cursor: pointer; }
.choice-options button span { display: block; font-size: 25px; }
.choice-options button small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 9px; }

.decor-launcher {
    position: absolute;
    z-index: 24;
    right: var(--safe-right);
    bottom: max(22px, env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 17px;
    border: 1px solid rgba(62,91,80,.14);
    border-radius: 24px;
    background: rgba(255,250,240,.96);
    color: var(--leaf-dark);
    box-shadow: var(--shadow-sm);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.decor-launcher svg { width: 22px; height: 22px; }

.drawer {
    position: absolute;
    z-index: 50;
    top: 82px;
    right: var(--safe-right);
    bottom: var(--safe-bottom);
    width: min(356px, calc(100vw - 24px));
    padding: 19px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 28px;
    background: rgba(255,253,248,.98);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(15px);
}

.drawer-header { display: grid; grid-template-columns: 72px 1fr 32px; align-items: center; gap: 9px; }
.drawer-header h2 { margin: 0; font-family: var(--font-display); font-size: 19px; text-align: center; }
.drawer-header small, .drawer-header strong { display: block; }
.drawer-header small { color: var(--ink-soft); font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.drawer-header strong { margin-top: 2px; color: #a36d18; font-size: 15px; }
.drawer-header button { width: 32px; height: 32px; border: 0; background: transparent; font-size: 25px; cursor: pointer; }
.drawer > p { margin: 16px 2px; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }

.decor-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.decor-option { position: relative; min-height: 102px; padding: 11px 8px; border: 1px solid rgba(58,93,78,.1); border-radius: 18px; background: #f2f5e9; text-align: left; cursor: pointer; }
.decor-option.selected { border-color: var(--leaf); box-shadow: inset 0 0 0 2px rgba(79,154,114,.17); }
.decor-option.locked { background: #f1eee6; }
.decor-option .decor-emoji { display: block; margin-bottom: 8px; font-size: 28px; }
.decor-option strong { display: block; font-size: 11px; }
.decor-option small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 9px; }
.decor-cost { position: absolute; top: 9px; right: 9px; color: #a36d18; font-size: 10px; font-weight: 800; }

.primary-button, .secondary-button, .danger-button {
    min-height: 46px;
    padding: 0 19px;
    border-radius: 17px;
    font-weight: 800;
    cursor: pointer;
}

.primary-button { border: 0; background: var(--leaf); color: #fff; box-shadow: 0 9px 20px rgba(54,120,90,.22); }
.secondary-button { border: 1px solid rgba(54,91,77,.17); background: #f2f4eb; color: var(--leaf-dark); }
.danger-button { border: 1px solid rgba(184,94,94,.2); background: #fff1ef; color: var(--danger); }
.drawer > .secondary-button { width: 100%; margin-top: 14px; }

.minigame-card {
    position: absolute;
    z-index: 44;
    top: 84px;
    left: 50%;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 12px;
    min-width: 320px;
    max-width: calc(100vw - 30px);
    padding: 12px 42px 12px 14px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(255,250,240,.97);
    box-shadow: var(--shadow-sm);
    transform: translateX(-50%);
}

.minigame-card > button { position: absolute; top: 7px; right: 8px; border: 0; background: none; font-size: 22px; cursor: pointer; }
.minigame-card > span { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 15px; background: #d8ebd3; font-size: 23px; }
.minigame-card strong { font-size: 13px; }
.minigame-card p { margin: 3px 0 0; color: var(--ink-soft); font-size: 10px; }
.minigame-progress { color: var(--leaf-dark); font-size: 12px; font-weight: 800; }

.toast-region { position: absolute; z-index: 90; top: 88px; left: 50%; display: grid; gap: 8px; width: min(360px, calc(100vw - 30px)); transform: translateX(-50%); pointer-events: none; }
.toast { padding: 11px 15px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,253,248,.97); box-shadow: var(--shadow-sm); color: var(--ink); font-size: 12px; text-align: center; animation: toast-in .25s ease both; }
.toast.good { background: rgba(235,248,226,.98); }
.toast.warn { background: rgba(255,244,218,.98); }

.save-indicator { position: absolute; z-index: 90; left: 50%; bottom: 12px; padding: 6px 12px; border-radius: 13px; background: rgba(37,74,62,.87); color: #fff; font-size: 10px; opacity: 0; transform: translate(-50%,8px); transition: opacity .25s ease, transform .25s ease; pointer-events: none; }
.save-indicator.visible { opacity: 1; transform: translate(-50%,0); }

.screen-layer {
    position: absolute;
    z-index: 120;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(218, 241, 232, .86);
    backdrop-filter: blur(12px);
}

#loading-screen { color: var(--ink); transition: opacity .4s ease; }
#loading-screen.is-leaving { opacity: 0; pointer-events: none; }
#loading-screen p { margin-top: 18px; font-size: 13px; font-weight: 800; }
.loading-mark { display: flex; align-items: flex-end; gap: 7px; height: 42px; }
.loading-mark span { width: 14px; height: 28px; border-radius: 100% 0 100% 0; background: var(--leaf); transform-origin: bottom; animation: sprout 1s ease-in-out infinite alternate; }
.loading-mark span:nth-child(2) { height: 40px; animation-delay: -.35s; }
.loading-mark span:nth-child(3) { height: 24px; animation-delay: -.7s; }

.welcome-screen, .return-screen { background: linear-gradient(rgba(220,244,236,.84), rgba(245,248,224,.91)); }
.welcome-card { width: min(470px, 100%); padding: 38px 42px 32px; border: 1px solid rgba(64,97,82,.13); border-radius: 38px; background: rgba(255,253,248,.97); box-shadow: var(--shadow-lg); text-align: center; }
.welcome-card.compact { width: min(420px,100%); }
.welcome-sprout { display: grid; place-items: center; width: 68px; height: 68px; margin: 0 auto 15px; border-radius: 24px; background: #e5f1d5; font-size: 35px; transform: rotate(-3deg); }
.welcome-card h1 { margin: 0; color: #285a4c; font-family: var(--font-display); font-size: clamp(30px, 5vw, 42px); line-height: 1.05; letter-spacing: -1.6px; }
.welcome-card p { margin: 18px auto 22px; max-width: 350px; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }
.welcome-card .primary-button { min-width: 235px; }
.welcome-card small { display: block; margin-top: 15px; color: #81918b; font-size: 10px; }

.game-dialog {
    width: min(590px, calc(100vw - 26px));
    max-height: min(720px, calc(100dvh - 30px));
    padding: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: var(--cream-solid);
    color: var(--ink);
    box-shadow: var(--shadow-lg);
}

.game-dialog::backdrop { background: rgba(25,58,48,.42); backdrop-filter: blur(5px); }
.game-dialog form { position: relative; padding: 30px; }
.game-dialog h2 { margin: 0 40px 24px 0; font-family: var(--font-display); font-size: 26px; letter-spacing: -.7px; }
.game-dialog form > p { color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.dialog-close { position: absolute; top: 17px; right: 17px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef3e8; color: var(--ink-soft); font-size: 25px; cursor: pointer; }
.help-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-bottom: 20px; }
.help-grid > div { padding: 16px; border-radius: 18px; background: #f2f4e9; }
.help-grid span { display: block; margin-bottom: 8px; font-size: 25px; }
.help-grid strong { font-size: 13px; }
.help-grid p { margin: 5px 0 0; color: var(--ink-soft); font-size: 11px; line-height: 1.45; }
.game-dialog .primary-button { width: 100%; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 0; border-top: 1px solid var(--line); cursor: pointer; }
.setting-row strong, .setting-row small { display: block; }
.setting-row strong { font-size: 13px; }
.setting-row small { margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
.setting-row input { width: 44px; height: 24px; accent-color: var(--leaf); cursor: pointer; }
.settings-actions { display: grid; grid-template-columns: repeat(2,1fr); gap: 9px; margin-top: 22px; }
.settings-actions .danger-button { grid-column: 1 / -1; }
.file-button { display: grid; place-items: center; font-size: 13px; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.journal-dialog { width: min(670px, calc(100vw - 26px)); }
.journal-full { display: grid; gap: 10px; }
.journal-full .event-item { padding: 12px; border: 0; border-radius: 16px; background: #f2f4e9; }
.journal-empty { padding: 24px; border-radius: 18px; background: #f2f4e9; color: var(--ink-soft); font-size: 12px; text-align: center; }
.rename-input { width: 100%; min-height: 52px; padding: 0 16px; border: 1px solid rgba(54,91,77,.2); border-radius: 16px; background: #fffdf8; color: var(--ink); font-size: 18px; font-weight: 800; }
.visitor-dialog { width: min(480px, calc(100vw - 26px)); text-align: center; }
.visitor-dialog h2 { margin-right: 0; }
.visitor-dialog .welcome-sprout { margin-bottom: 18px; }
#panel-piti-name[role="button"] { border-radius: 7px; cursor: pointer; }

@keyframes sprout { from { transform: scaleY(.72) rotate(-4deg); } to { transform: scaleY(1.06) rotate(4deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (max-width: 1180px) {
    .piti-dock { grid-template-columns: 120px minmax(220px,280px) minmax(300px,1fr); width: calc(100vw - 290px); min-height: 144px; }
    .portrait-wrap { width: 112px; height: 112px; }
    #piti-portrait { width: 112px; height: 112px; }
    .piti-actions { gap: 6px; padding-left: 11px; }
    .piti-actions button { min-height: 72px; }
    .journal-panel { width: 220px; }
}

@media (max-width: 900px) {
    .mobile-only { display: flex !important; }
    .journal-panel, .request-card {
        position: absolute;
        z-index: 65;
        top: 78px;
        right: var(--safe-right);
        left: auto;
        width: min(290px, calc(100vw - 24px));
    }
    .journal-panel:not(.mobile-open), .request-card:not(.mobile-open) { display: none; }
    .mobile-rail { position: absolute; z-index: 28; top: 82px; left: var(--safe-left); flex-direction: column; gap: 7px; }
    .mobile-rail button { display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,250,240,.94); box-shadow: var(--shadow-sm); color: var(--ink); font-size: 9px; font-weight: 800; }
    .mobile-rail button span:first-child { font-size: 15px; }
    .request-card { top: 126px; }
    .piti-dock { grid-template-columns: 100px minmax(0,1fr); gap: 10px; width: min(590px, calc(100vw - 24px)); padding: 12px 14px; border-radius: 28px; }
    .portrait-wrap { width: 94px; height: 94px; }
    #piti-portrait { width: 94px; height: 94px; }
    .portrait-mood { width: 29px; height: 29px; font-size: 14px; }
    .piti-actions { grid-column: 1 / -1; grid-template-columns: repeat(5,1fr); padding: 9px 0 0; border-top: 1px solid var(--line); border-left: 0; }
    .piti-actions button { min-height: 57px; border-radius: 15px; }
    .piti-actions button > span:first-child { min-height: 22px; font-size: 21px; }
    .decor-launcher { bottom: auto; top: 82px; }
    .choice-tray { bottom: 235px; }
}

@media (max-width: 600px) {
    .topbar { align-items: center; }
    .brand-lockup { min-width: 112px; padding: 8px 14px 9px; border-radius: 22px; }
    .brand-lockup::before, .brand-lockup::after { display: none; }
    .brand-line { font-size: 14px; }
    .brand-world { margin-top: 3px; font-size: 20px; letter-spacing: -.8px; }
    .brand-world i { width: 9px; height: 6px; right: 5px; }
    .world-status { min-width: 0; margin: 0 0 0 7px; padding: 7px 9px; border-radius: 17px; }
    .weather-icon { font-size: 18px; }
    .world-status strong { font-size: 10px; }
    .world-status small { font-size: 8px; }
    .top-actions { gap: 5px; }
    .icon-button { width: 38px; height: 38px; }
    .icon-button svg { width: 18px; height: 18px; }
    #btn-help { display: none; }
    .preview-badge { top: calc(var(--safe-top) + 64px); left: var(--safe-left); font-size: 8px; }
    .mobile-rail { top: 76px; }
    .mobile-rail button { width: 40px; min-height: 40px; justify-content: center; padding: 0; }
    .mobile-rail button span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
    .decor-launcher { top: 76px; width: 42px; min-height: 42px; padding: 0; justify-content: center; }
    .decor-launcher span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
    .decor-launcher svg { width: 21px; }
    .camera-tools { top: 46%; right: 8px; gap: 5px; }
    .small-icon-button { width: 37px; height: 37px; }
    .piti-dock { bottom: var(--safe-bottom); grid-template-columns: 76px minmax(0,1fr); gap: 9px; width: calc(100vw - 16px); min-height: 0; padding: 10px 11px 11px; border-radius: 25px; }
    .portrait-wrap { width: 70px; height: 70px; border-width: 4px; }
    #piti-portrait { width: 70px; height: 70px; }
    .portrait-mood { width: 25px; height: 25px; right: -1px; bottom: -1px; border-width: 2px; font-size: 12px; }
    .piti-name-row { grid-template-columns: 24px minmax(0,1fr) 24px; gap: 3px; }
    .piti-name-row h2 { font-size: 17px; }
    .piti-name-row p { font-size: 8px; }
    .mini-nav { width: 24px; height: 28px; font-size: 19px; }
    .trait-list { margin-top: 4px; }
    .trait-badge { padding: 2px 6px; font-size: 7px; }
    .needs-compact { gap: 3px; margin-top: 5px; }
    .needs-compact > div { grid-template-columns: 37px minmax(45px,1fr) 26px; gap: 4px; font-size: 7px; }
    .needs-compact output { font-size: 7px; }
    .piti-actions { gap: 5px; padding-top: 8px; }
    .piti-actions button { min-width: 0; min-height: 51px; padding: 6px 2px; border-radius: 13px; font-size: 7px; }
    .piti-actions button > span:first-child { min-height: 20px; font-size: 18px; }
    .piti-actions button:nth-child(5) > span:first-child { font-size: 8px; }
    .dock-close { top: 3px; right: 4px; width: 25px; height: 25px; font-size: 19px; }
    .choice-tray { bottom: calc(var(--safe-bottom) + 172px); padding: 10px; }
    .choice-options { gap: 4px; }
    .choice-options button { min-height: 56px; border-radius: 12px; }
    .choice-options button span { font-size: 21px; }
    .drawer { top: 68px; right: 7px; bottom: 7px; width: calc(100vw - 14px); padding: 16px; border-radius: 24px; }
    .minigame-card { top: 75px; width: calc(100vw - 96px); min-width: 0; grid-template-columns: 35px 1fr; padding: 9px 32px 9px 10px; }
    .minigame-card > span { width: 35px; height: 35px; font-size: 19px; }
    .minigame-progress { grid-column: 2; }
    .toast-region { top: 124px; }
    .welcome-card { padding: 30px 22px 25px; border-radius: 30px; }
    .welcome-card p { font-size: 12px; }
    .help-grid { grid-template-columns: 1fr; }
    .game-dialog form { padding: 24px 20px; }
    .settings-actions { grid-template-columns: 1fr; }
    .settings-actions .danger-button { grid-column: auto; }
}

@media (max-height: 670px) and (orientation: landscape) {
    .journal-panel { top: 75px; max-height: calc(100dvh - 90px); overflow: auto; }
    .request-card { top: 75px; }
    .piti-dock { left: 12px; bottom: 10px; width: min(720px, calc(100vw - 100px)); transform: none; }
    .portrait-wrap { width: 70px; height: 70px; }
    #piti-portrait { width: 70px; height: 70px; }
    .piti-dock { grid-template-columns: 75px 205px minmax(290px,1fr); min-height: 92px; padding: 9px; }
    .piti-actions { grid-column: auto; border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 8px; }
    .piti-actions button { min-height: 55px; }
    .needs-compact { display: none; }
    .choice-tray { left: auto; right: 12px; bottom: 108px; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
