* { box-sizing: border-box; }
html { font-size: 16px; scroll-padding-bottom: 120px; }
body { margin: 0; line-height: 1.55; padding: max(12px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
.shell { max-width: 1040px; margin: auto; }
.topbar { display: grid; grid-template-columns: minmax(0, 1fr) 72px; align-items: center; gap: 12px; padding: 16px; }
.brand { min-width: 0; white-space: nowrap; overflow: hidden; color: inherit; text-decoration: none; letter-spacing: .06em; font-weight: bold; }
.topbar-controls { display: grid; grid-template-columns: minmax(0, 1fr) 48px; align-items: center; gap: 8px; }
#app-settings { flex: none; width: 48px; min-height: 48px; padding: 0; text-align: center; }
.brand small { display: block; font-size: .7rem; letter-spacing: .12em; overflow: hidden; text-overflow: ellipsis; }
#city-progress { letter-spacing: .04em; white-space: normal; }
#connection { display: flex; align-items: center; justify-content: end; height: 48px; font-size: .75rem; line-height: 1.25; text-align: right; }
#sandbox { padding: 8px 0; color: var(--accent); font-size: .8rem; }
#hud:empty { display: none; }
#hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 16px; margin-top: 12px; }
.resource span, .resource small { display: block; }
.resource { min-width: 0; display: flex; flex-direction: column; overflow-wrap: break-word; }
.resource-heading { display: flex; flex-direction: column; flex: 1; }
.resource strong { display: block; font-size: 1.05rem; line-height: 1.4; }
.resource-heading > small:first-child { min-height: 1.6em; }
.resource-meter strong { min-height: 1.4em; }
.resource .timer { display: block; min-height: calc(1.4em + 4px); margin-top: auto; padding-top: 4px; font-size: .75rem; line-height: 1.4; color: var(--muted); font-variant-numeric: tabular-nums; }
.worm-reserves { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.worm-ordinary, .magic-worm-reserve { min-width: 0; }
.worm-reserves strong, .worm-reserves .timer { white-space: nowrap; }
.magic-worm-reserve { text-align: right; }
.magic-worm-reserve strong, .magic-worm-reserve .timer { color: var(--accent); }
.worm-reserves .timer { margin-bottom: 0; }
.countdown-timer { display: block; font-size: .75rem; line-height: 1.3; color: var(--muted); }
.resource-hero { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.resource-hero, .resource-quests { grid-column: 1 / -1; }
.resource-money { grid-column: span 2; }
.resource-hero button { flex: none; min-height: 44px; }
progress { width: 100%; height: 8px; display: block; margin-top: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button { min-height: 48px; padding: 10px 14px; cursor: pointer; text-align: left; text-decoration: none; touch-action: manipulation; overflow-wrap: anywhere; }
.panel { padding: 20px; margin-bottom: 16px; overflow-wrap: anywhere; }
h1, h2, h3, p { margin: 0 0 12px; }
h1 { font-size: 1.6rem; line-height: 1.3; }
h2 { font-size: 1.1rem; }
.kicker { font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.art { display: flex; justify-content: center; align-items: center; text-align: center; padding: 12px; aspect-ratio: 16/9; position: relative; overflow: hidden; }
.art img { width: 100%; height: 100%; position: absolute; inset: 0; object-fit: contain; image-rendering: pixelated; }
.item-art { isolation: isolate; }
.item-art .item-bg { z-index: 0; object-fit: cover; }
.item-art .item-picture { z-index: 1; padding: 14%; }
.item-art .item-frame, .item-art .item-silhouette { z-index: 2; }
.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.section-grid .panel { margin: 0; }
.button-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.button-row button { flex: 1 1 120px; font-size: .9rem; }
.button-row .action-reason { flex-basis: 100%; }
.button-grid button { min-height: 64px; }
.details p { white-space: pre-line; }
.quest-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--edge-light); }
.quest-entry h3 { margin-bottom: 6px; }
.quest-entry p { margin-bottom: 4px; }
.quest-entry button { min-width: 156px; }
@media (max-width: 600px) { .quest-entry { grid-template-columns: 1fr; } .quest-entry button { width: 100%; } }
.travel-notice > button { display: block; width: 100%; margin-top: 8px; }
.travel-actions > button, .travel-actions .button-row button { display: block; width: 100%; min-width: 0; }
.travel-actions .button-row { display: block; }
.upgrade-row { display: grid; grid-template-columns: minmax(0, 1fr) 144px; gap: 16px; align-items: center; padding: 16px 0; border-top: 1px solid var(--edge-light); }
.upgrade-copy { min-width: 0; }
.upgrade-copy h3 { font-size: 1.05rem; margin: 0 0 6px; }
.upgrade-copy p { font-size: .9rem; margin: 0 0 6px; }
.upgrade-level { display: block; font-variant-numeric: tabular-nums; }
.upgrade-copy progress { margin: 6px 0 10px; }
.upgrade-row:not(:has(.upgrade-controls)) .upgrade-copy { grid-column: 1 / -1; }
.upgrade-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.upgrade-controls button { min-height: 64px; padding: 8px; text-align: center; font-size: .85rem; line-height: 1.35; }
.upgrade-history { border-top: 1px solid var(--edge-light); padding-top: 14px; margin-top: 8px; }
.upgrade-history p { font-size: .8rem; margin-bottom: 6px; }
#fund-dialog { width: min(480px, calc(100% - 24px)); padding: 0; }
.fund-dialog-surface { position: relative; padding: 24px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
#fund-close { position: absolute; top: 8px; right: 8px; width: 48px; min-height: 48px; padding: 0; text-align: center; font-size: 1.5rem; }
#fund-title { padding-right: 48px; }
#fund-amount { display: block; text-align: center; font-size: 1.15rem; margin: 16px 0; }
#fund-percent { margin: 8px 0 12px; accent-color: var(--accent); }
#fund-donate { display: block; width: 100%; text-align: center; margin-top: 16px; }
@media (max-width: 480px) { .upgrade-row { grid-template-columns: minmax(0, 1fr) 112px; gap: 12px; } }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin: 16px 0; }
.slot { min-width: 0; border: 1px solid var(--edge-light); padding: 6px; text-align: center; font-size: .7rem; }
.slot .art { aspect-ratio: 1; font-size: .7rem; padding: 4px; }
.slot span { display: block; overflow-wrap: anywhere; }
.slots { list-style: none; padding: 0; }
.collection-group .slots { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.collection-group .slot { padding: 4px; font-size: .75rem; }
.slot-name { margin-top: 6px; hyphens: auto; }
.slot-count { min-height: 1.55em; color: var(--muted); }
.collection-menu-list { display: grid; gap: 8px; }
.collection-menu-list button { width: 100%; min-height: calc(3.1em + 24px); }
.collection-city { margin-top: 12px; border-top: 1px solid var(--edge-light); }
.collection-city > summary { min-height: 64px; padding: 16px 0; cursor: pointer; touch-action: manipulation; }
.repeat-actions .button-row { display: grid; grid-template-columns: minmax(0, 1fr); }
.repeat-actions .button-row button { min-height: 64px; }
.repeat-description { height: 24rem; overflow-y: auto; scrollbar-gutter: stable; }
.repeat-description p { font-size: .9rem; line-height: 1.45; margin-bottom: 8px; }
.dummy-description { height: 11rem; }
.repeat-drop { height: 15rem; overflow-y: auto; scrollbar-gutter: stable; }
.repeat-drop .slots { grid-template-columns: repeat(auto-fill, minmax(0, min(132px, 100%))); justify-content: start; margin: 8px 0 0; }
.repeat-drop .slot-name { min-height: 3.1em; }
.creation-heading, .settings-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.creation-heading button, .settings-heading button { flex: none; min-width: 48px; min-height: 48px; text-align: center; }
#settings-content { display: grid; gap: 12px; }
#settings-content button[aria-pressed="true"] { outline: 2px solid var(--accent); }
#settings-status { min-height: 1.5em; margin-top: 16px; }
.slot-button { display: block; width: 100%; height: 100%; min-height: 48px; padding: 0; text-align: center; }
.item-detail-surface { position: relative; padding: 24px; }
.item-detail-layout { display: grid; grid-template-columns: minmax(100px, 42%) minmax(0, 1fr); gap: 20px; align-items: start; }
.item-detail-identity { min-width: 0; }
.item-detail-identity > .art { aspect-ratio: 1; width: 100%; padding: 0; }
.item-detail-info { min-width: 0; padding-top: 48px; overflow-wrap: anywhere; }
.item-detail-title { margin: 12px 0 4px; }
.item-detail-stat { margin: 0 0 8px; font-weight: bold; }
.item-detail-condition { margin: 0 0 8px; font-size: .86rem; }
.item-detail-rarity { margin: 0; font-size: .85rem; color: var(--accent); }
.item-detail-description { margin: 2lh 0 0; white-space: pre-line; }
#item-detail { width: min(680px, calc(100% - 24px)); max-height: min(88vh, 760px); padding: 0; overflow: auto; }
#item-detail-close { position: absolute; top: 8px; right: 8px; width: 48px; height: 48px; flex: none; padding: 0; text-align: center; font-size: 1.5rem; line-height: 1; z-index: 3; }
@media (max-width: 440px) { .item-detail-surface { padding: 16px; } .item-detail-layout { grid-template-columns: minmax(90px, 42%) minmax(0, 1fr); gap: 16px; } .item-detail-title { font-size: 1rem; } }
.collection-group > summary { min-height: 48px; padding: 10px 0; cursor: pointer; touch-action: manipulation; }
.collection-progress { margin-left: 12px; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.collection-group .collection-group { margin-top: 16px; }
.collection-group > .collection-group + .collection-group { border-top: 1px solid var(--edge-light); padding-top: 16px; }
.collection-group p { font-size: .85rem; }
.compact-collection { max-width: 680px; margin-inline: auto; }
.compact-collection.panel { max-width: 724px; }
.compact-collection > h2, .compact-collection > h3 { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.compact-collection > h2 > span:first-child, .compact-collection > h3 > span:first-child { min-width: 0; }
.compact-collection .collection-progress { margin-left: 0; font-size: .9em; }
.collection-group .compact-collection .slots, .collection-group.compact-collection .slots { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.compact-collection .slot { position: relative; padding: 0; }
.compact-collection .slot-button { display: block; width: 100%; min-height: 0; padding: 0; }
.compact-collection .slot-name { display: none; }
.compact-collection .slot-count { position: absolute; right: 2px; bottom: 2px; min-height: 0; max-width: calc(100% - 4px); padding: 0 2px; background: var(--surface); font-size: .65rem; line-height: 1.3; pointer-events: none; }
.compact-collection .slot-count:empty { display: none; }
@media (max-width: 480px) { .collection-group .compact-collection .slots, .collection-group.compact-collection .slots { gap: 6px; } }
#nav { position: sticky; bottom: max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; padding: 8px; margin-top: 20px; z-index: 2; }
#nav a { min-width: 0; min-height: 52px; display: flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; font-size: .85rem; padding: 4px; overflow-wrap: anywhere; }
footer { font-size: .7rem; padding: 16px 0 max(16px, env(safe-area-inset-bottom)); text-align: center; }
#notice, #pending { margin: 12px 0; padding: 12px; }
dialog { color: var(--text); width: min(480px, calc(100% - 32px)); max-height: 80vh; padding: 24px; }
dialog button { flex: 1; text-align: center; }
label { display: block; margin-bottom: 16px; }
input { display: block; padding: 12px; min-height: 48px; width: 100%; margin-top: 6px; }
select { display: block; padding: 12px; min-height: 48px; width: 100%; margin-top: 6px; font: inherit; }
.hero-profile { display: grid; grid-template-columns: minmax(100px, 180px) minmax(0, 1fr); gap: 24px; align-items: start; }
.hero-avatar { width: 100%; padding: 4px; text-align: center; }
.hero-avatar .art, .avatar-choice .art { aspect-ratio: 1; padding: 0; border: 0; }
.hero-avatar > span { display: block; font-size: .8rem; padding: 6px 0; }
.hero-info { min-width: 0; }
.hero-info p { margin-bottom: 8px; }
.hero-name { margin-bottom: 12px; }
.hero-identity-row { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: 8px; }
.hero-identity-row .hero-name { min-width: 0; flex: 1 1 120px; }
.hero-identity-row .switch-hero { flex: 0 0 auto; max-width: 100%; min-width: 0; }
.hero-name small { display: block; font-size: .75rem; }
.name-edit { max-width: 100%; font-size: 1.15rem; padding: 8px; font-weight: bold; }
.hero-profession { color: var(--accent); }
.hero-name .actions { gap: 8px; }
.hero-name .actions button { font-size: .8rem; padding: 8px; }
.free-points { padding: 12px; border: 1px solid var(--accent); color: var(--accent); font-weight: bold; }
.stat-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--stat-value-width, 4ch) repeat(3, 52px); gap: 8px; align-items: center; margin-top: 12px; }
.stat-label { display: contents; }
.stat-label span { overflow-wrap: anywhere; }
.stat-label .stat-name { min-width: 0; white-space: nowrap; }
.stat-label strong { min-width: 0; text-align: right; white-space: normal; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat-row button { min-height: 48px; padding: 4px; text-align: center; }
.stat-row.stat-row-long { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-row-long .stat-label { display: flex; grid-column: 1 / -1; min-width: 0; flex-direction: column; gap: 4px; }
.stat-row-long .stat-label strong { text-align: left; }
.avatar-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.avatar-choice { padding: 4px; text-align: center; }
.avatar-choice[aria-pressed="true"] { outline: 2px solid var(--accent); }
.creation-avatars { min-width: 0; margin: 0 0 16px; padding: 12px; border: 1px solid var(--edge-light); }
.creation-avatars .avatar-options { margin: 8px 0 0; }
.creation-avatar-option { min-width: 0; margin: 0; cursor: pointer; border: 2px solid transparent; overflow-wrap: anywhere; }
.creation-avatar-option:has(input:checked) { border-color: var(--accent); }
.creation-avatar-option input { width: 24px; height: 24px; min-height: 0; margin: 4px auto 8px; accent-color: var(--accent); }
.creation-avatar-option:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.creation-avatar-option:active { background: var(--surface-raised); }
.creation-avatar-option > span { display: block; padding: 8px 4px; }
@media (max-width: 480px) {
  .hero-profile { grid-template-columns: minmax(88px, .85fr) minmax(0, 1.4fr); gap: 12px; }
  .panel.hero-stats { padding: 12px 8px; }
  .stat-row { grid-template-columns: minmax(0, 1fr) var(--stat-value-width, 4ch) repeat(3, 44px); gap: 4px; font-size: .8rem; }
  .stat-row button { font-size: .75rem; }
  .hero-name input { padding: 8px; }
}
form { max-width: 560px; }
main { min-height: 280px; }
#debug-drawer { position: fixed; top: 25dvh; left: max(0px, env(safe-area-inset-left)); z-index: 10; display: flex; align-items: flex-start; max-height: 70dvh; }
#debug-toggle { width: 44px; min-height: 48px; padding: 0; text-align: center; flex: none; }
#debug-tools { width: min(320px, calc(100vw - 44px)); max-height: 70dvh; overflow-y: auto; margin: 0; padding: 12px; box-shadow: 0 8px 24px #0008; }
#debug-tools button { display: block; width: 100%; margin-top: 8px; }
.roster-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; }
.roster-member { margin: 0; }
.switch-hero { margin: 0 0 12px; }
.character-list { display: grid; gap: 12px; margin-bottom: 16px; }
.character-count { text-align: right; }
.character-row { display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px; border: 1px solid var(--edge-light); background: var(--surface); }
.character-selected { border-color: var(--accent); }
.character-portrait { width: 88px; aspect-ratio: 1; padding: 0; }
.character-portrait img { object-fit: cover; }
.character-info { min-width: 0; }
.character-info h2, .character-info p { margin-bottom: 4px; }
.character-info p { font-size: .85rem; }
.character-controls { display: grid; gap: 8px; }
.character-controls button { min-width: 92px; text-align: center; }
@media (max-width: 600px) {
  .character-row { grid-template-columns: 64px minmax(0, 1fr) 80px; gap: 8px; padding: 8px; }
  .character-portrait { width: 64px; }
  .character-info h2 { font-size: .9rem; }
  .character-info p { font-size: .7rem; }
  .character-controls button { min-width: 0; padding: 6px 2px; font-size: .68rem; min-height: 44px; }
}
[hidden] { display: none !important; }
@media (max-width: 600px) {
  .topbar { padding: 12px; } .brand { font-size: .85rem; }
  #hud { grid-template-columns: 1fr 1fr; padding: 12px; gap: 12px; }
  .resource-money { grid-column: span 1; }
  .section-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; } h1 { font-size: 1.35rem; }
  #nav { gap: 4px; padding: 4px; } #nav a { font-size: .7rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
@media (max-width: 359px) {
  .topbar { gap: 8px; }
  .resource-worms { grid-column: 1 / -1; }
  .collection-group .slots { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
