:root {
  --ink: #000066;
  --muted: #404080;
  --paper: #ffffc0;
  --surface: #fffedc;
  --line: #000066;
  --green: #99ff66;
  --green-dark: #5dcc35;
  --red: #f00000;
  --orange: #e99a32;
  --blue: #7dd8e8;
  --game: #ffffc0;
  --shadow: 4px 5px 0 rgba(0, 0, 102, .2);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  background-image: linear-gradient(rgba(255,255,255,.18) 1px, transparent 1px);
  background-size: 100% 12px;
  font-family: Verdana, Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--ink); font-weight: 700; text-underline-offset: 2px; }
a:hover { color: var(--green); }
button, input { font: inherit; }
button, .button {
  display: inline-block;
  border: 0;
  border: 2px solid var(--ink);
  border-radius: 4px;
  min-height: 2.75rem;
  padding: .65rem .85rem;
  color: var(--ink);
  background: var(--green);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 2px 2px 0 rgba(0, 0, 102, .24);
  transition: transform .1s ease, background .1s ease;
}
button:hover, .button:hover { color: var(--ink); background: var(--green); box-shadow: 2px 2px 0 rgba(0, 0, 102, .24); transform: translate(-1px, -1px); }
button:disabled { cursor: default; opacity: .55; transform: none; box-shadow: none; }
.button.secondary, button.secondary { color: var(--ink); background: var(--blue); }
.button.secondary:hover, button.secondary:hover { color: var(--ink); background: #a9eaf3; }

.page-shell { max-width: 1180px; margin: 0 auto; padding: 1.5rem .85rem 3rem; }
.narrow { max-width: 760px; }
.eyebrow { margin: 0 0 .4rem; color: var(--red); font-size: .9rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3 { margin-top: 0; font-family: 'Trebuchet MS', Arial, sans-serif; line-height: 1.15; }
h1 { max-width: 700px; font-size: clamp(2rem, 11vw, 4.3rem); }
h2 { font-size: 1.55rem; }
.lede { max-width: 650px; color: var(--muted); font-size: 1.08rem; }
.intro-actions, .page-actions, .game-heading-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.page-actions { margin: 1rem 0; }
.editor-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .7rem; }
.editor-heading .eyebrow { margin: 0; }
.back-link { flex: 0 0 auto; margin: 0; text-decoration: none; }
.surface { border: 3px solid var(--line); border-radius: 5px; background: var(--surface); box-shadow: var(--shadow); }

.game-page { background: var(--game); }
.game-shell { max-width: 1160px; margin: 0 auto; padding: .85rem .5rem 2.25rem; }
.game-heading { display: flex; align-items: flex-start; flex-direction: column; gap: .85rem; margin: .35rem 0 1rem; }
.game-heading h1 { margin: 0; font-size: clamp(1.8rem, 10vw, 3.25rem); overflow-wrap: anywhere; }
.game-heading-actions { width: auto; max-width: 100%; }
.game-heading-actions .button { flex: 0 1 auto; text-align: center; }
.reset-button { position: absolute; top: .45rem; right: .45rem; z-index: 3; min-height: 2rem; padding: .25rem .5rem; font-size: .8rem; }
.game-frame { position: relative; display: flex; justify-content: center; width: 100%; max-width: 1100px; min-height: 0; margin-inline: auto; aspect-ratio: 570 / 400; padding: 0; border: 3px solid var(--ink); border-radius: 5px; background: var(--game); box-shadow: var(--shadow); overflow: hidden; }
.game-frame embed, .game-frame ruffle-embed { display: block; width: 100%; height: 100%; border-radius: 0; }
.game-loading { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; color: var(--ink); background: rgba(255,255,192,.94); font-weight: 700; }
.game-frame.is-ready .game-loading { display: none; }
.mobile-control-hint { display: none; margin: .55rem 0 0; color: var(--muted); font-size: .9rem; text-align: center; }
.tiles-scroll-hint { display: none; margin: .4rem 0 0; color: var(--muted); font-size: .85rem; text-align: center; }
.spinner { width: 1.1rem; height: 1.1rem; margin-right: .55rem; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; vertical-align: -.2rem; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.game-meta { display: flex; align-items: center; flex-wrap: wrap; gap: .85rem; margin-top: .8rem; padding: .75rem; border: 3px solid rgba(0,0,102,.28); border-radius: 5px; background: rgba(255,255,255,.45); box-shadow: var(--shadow); }
.vote-group, .game-actions { display: flex; align-items: center; flex-wrap: nowrap; gap: .55rem; }
.game-meta .vote-group { flex: 1 1 300px; min-width: 0; }
.game-meta .game-actions { flex: 0 0 auto; }
.share-button { display: inline-flex; align-items: center; gap: .35rem; }
.share-button span { font-size: 1.15em; line-height: 1; }
.vote-button { width: 2.35rem; height: 2.35rem; padding: .4rem; border: 2px solid var(--ink); background: rgba(255,255,255,.55); }
.vote-button:hover { background: #fff; }
.vote-button img { width: 100%; height: 100%; object-fit: contain; }
.score { min-width: 2rem; text-align: center; font-weight: 700; }
.meta-label { color: #696a44; font-size: 1rem; }
.site-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: .8rem 1.2rem; max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 1.75rem; color: var(--muted); font-size: .9rem; }
.site-footer a { color: var(--muted); font-weight: 400; }

.table-wrap { overflow-x: auto; margin-top: 1rem; border: 2px solid var(--line); border-radius: 5px; background: var(--surface); box-shadow: var(--shadow); }
#worlds { width: 100%; table-layout: fixed; border-collapse: collapse; }
#worlds th, #worlds td { padding: .85rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
#worlds td, #worlds th { border: 1px solid #d6d6a8; word-wrap: break-word; }
#worlds th { color: var(--ink); background: var(--blue); font-size: .95rem; letter-spacing: .04em; text-transform: uppercase; cursor: pointer; white-space: nowrap; }
#worlds th:nth-child(1), #worlds td:nth-child(1) { width: 42%; }
#worlds th:nth-child(2), #worlds td:nth-child(2) { width: 25%; }
#worlds th:nth-child(3), #worlds td:nth-child(3) { width: 33%; }
#worlds th:hover { color: var(--ink); }
#worlds tr:last-child td { border-bottom: 0; }
#worlds tbody tr:hover { background: #fffbd0; }
.sort-symbol.asc::after { content: '▲'; }
.sort-symbol.desc::after { content: '▼'; }
.table-status { padding: 2rem; color: var(--muted); text-align: center; font-size: 1rem; }
.table-status.error { color: #9a4a3b; }
.pagination { display: flex; align-items: center; justify-content: center; gap: .65rem; margin-top: .8rem; }
.pagination input { width: 4.5rem; padding: .65rem; border: 1px solid var(--line); border-radius: 7px; text-align: center; }
.pagination button { min-height: 2.35rem; padding: .4rem .65rem; }
.share-menu { position: absolute; right: 0; bottom: calc(100% + .5rem); z-index: 5; display: none; min-width: 12rem; padding: .55rem; border: 2px solid var(--ink); border-radius: 4px; background: var(--surface); box-shadow: var(--shadow); }
.share-menu.is-open { display: grid; gap: .35rem; }
.share-menu a, .share-menu button { display: block; width: 100%; min-height: 2.25rem; padding: .4rem .55rem; text-align: left; }
.share-menu a { color: var(--ink); background: var(--blue); border: 2px solid var(--ink); border-radius: 4px; text-decoration: none; }
.share-menu a:hover { color: var(--ink); background: #a9eaf3; }
.share-menu button { box-shadow: none; }
.share-control { position: relative; }
.game-meta .game-actions { margin-left: auto; }

.editor-layout { display: grid; grid-template-columns: 1fr; gap: .75rem; padding: .65rem; }
.editor-board { overflow: hidden; padding: 1rem; background: #e9f6f4; }
.editor-board canvas { display: block; width: 100%; max-width: 600px; height: auto; margin: 1rem auto 0; cursor: pointer; }
#hotbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); align-content: start; gap: .3rem; max-height: 15rem; overflow-y: auto; overflow-x: hidden; padding: .45rem; border: 2px solid rgba(0,0,102,.2); background: rgba(255,255,255,.35); }
#hotbar > div { width: 48px !important; height: 48px; display: block !important; border-radius: 3px !important; }
#hotbar img { display: block; width: 48px; height: 48px; object-fit: contain; }
.horizontal_scroll { overflow-x: auto; white-space: nowrap; }
.prevent-select { -webkit-user-select: none; -ms-user-select: none; user-select: none; }
.level-sidebar { display: flex; min-height: 0; flex-direction: column; padding: .75rem; background: #e9f6f4; }
#sortable { display: flex; min-height: 0; flex: 1 1 auto; flex-direction: column; width: 100%; height: auto; margin: 0; padding: 0; gap: .35rem; overflow-y: auto; list-style: none; }
#sortable li { flex: 0 0 120px; height: 120px !important; min-height: 120px; margin: 0 !important; padding: .25rem !important; border: 2px solid var(--line); border-radius: 5px; background: #fff; box-shadow: 2px 3px 0 rgba(0,0,102,.15); }
#sortable li { position: relative; overflow: hidden; cursor: grab; }
#sortable.sortable-drag { cursor: grabbing; }
#sortable .sortable-ghost { opacity: .45; background: var(--blue); }
#sortable li canvas { display: block; width: 100% !important; height: auto !important; max-height: 96px; object-fit: contain; }
#sortable li .level-delete { position: absolute; top: .3rem; right: .3rem; z-index: 1; width: 1.6rem; height: 1.6rem; padding: 0; border: 2px solid var(--red); color: var(--red); background: #fff; box-shadow: none; font-size: 1rem; line-height: 1; }
#sortable li .level-delete:hover { color: #fff; background: var(--red); }
.level-sidebar > button { display: block; width: 100%; margin-top: auto; }
.preview-panel { margin-top: .75rem; padding: .75rem; background: var(--game); }
.preview-panel .game-frame { border: 0; box-shadow: none; }
.publish-row { display: flex; align-items: stretch; flex-direction: column; gap: .55rem; margin-top: .85rem; }
.publish-row input { width: 100%; min-width: 0; padding: .72rem; border: 1px solid #c6c8a5; border-radius: 7px; }
.warning { color: #6f6331; font-size: 1rem; }
#advancedOptions { overflow-x: auto; display: none; }
#xml_text { width: 100%; margin-top: .8rem; padding: 1rem; border: 2px solid var(--line); border-radius: 5px; font: .9rem/1.5 monospace; }
.editor-status { color: var(--muted); font-size: 1rem; }
.tile-dragging { outline: 3px solid var(--red); outline-offset: 2px; }
.xml-help { margin: .7rem 0 0; color: var(--muted); font-size: .95rem; }

.error-panel { max-width: 640px; margin: 8vh .85rem; padding: 1.5rem 1rem; text-align: center; }
.error-panel h1 { margin-left: auto; margin-right: auto; font-size: 2.5rem; }
.contact-card { max-width: 620px; margin: 0 auto; padding: 2rem; }
.contact-card address { font-style: normal; font-size: 1.15rem; }

@media (max-width: 760px) {
  .game-shell { padding-inline: .7rem; }
  .game-heading { gap: .55rem; }
  .game-heading h1 { font-size: clamp(1.65rem, 8vw, 2.5rem); }
  .game-heading-actions { gap: .35rem; }
  .game-heading-actions .button { min-height: 2.35rem; padding: .4rem .55rem; font-size: .82rem; }
  .game-page .lede { font-size: 1.18rem; line-height: 1.55; }
  .game-meta { align-items: center; flex-direction: row; justify-content: space-between; gap: .45rem; border-width: 3px; padding: .55rem; }
  .game-meta button, .game-meta .button { min-height: 2.35rem; padding: .4rem .55rem; font-size: .85rem; }
  .game-meta .vote-group { min-width: 0; flex: 1 1 auto; gap: .3rem; overflow: hidden; }
  .game-meta .game-actions { flex: 0 0 auto; gap: .3rem; }
  .game-meta .meta-label { min-width: 0; font-size: .78rem; white-space: nowrap; }
  .game-meta .score { min-width: 1.35rem; }
  .site-footer { font-size: 1rem; line-height: 1.6; }
  .page-shell { padding-inline: 1rem; }
  .page-shell h1 { font-size: clamp(1.8rem, 9vw, 3rem); }
  .page-shell .lede { font-size: 1.15rem; line-height: 1.55; }
  .table-wrap { border-width: 3px; }
  #worlds th, #worlds td { padding: .65rem .4rem; font-size: .82rem; overflow-wrap: anywhere; }
  #worlds th { font-size: .78rem; white-space: nowrap; }
  .pagination, .pagination input { font-size: 1rem; }
  .pagination { flex-wrap: nowrap; gap: .25rem; }
  .pagination button { flex: 0 1 auto; min-height: 2.2rem; padding: .35rem .4rem; font-size: .78rem; white-space: nowrap; }
  .pagination input { width: 3.2rem; padding: .45rem .2rem; }
  .pagination label { flex: 0 1 auto; font-size: .82rem; white-space: nowrap; }
  .editor-heading h1 { font-size: 1.8rem; }
  .editor-layout { grid-template-columns: minmax(0, 1fr) 118px; gap: .4rem; padding: .4rem; border-width: 3px; }
  .editor-board { min-width: 0; padding: .55rem; }
  .level-sidebar { min-width: 0; padding: .45rem; }
  #sortable { min-height: 0; }
  #sortable li { flex-basis: 108px; height: 108px !important; min-height: 108px; }
  #sortable li canvas { max-height: 82px; }
  .preview-panel { border-width: 3px; }
  .publish-row label, .advanced, .xml-help { font-size: 1.05rem; }
  .warning { font-size: 1.05rem; line-height: 1.5; }
  #xml_text { font-size: 1rem; min-height: 22rem; }
}

@media (pointer: coarse) {
  .mobile-control-hint { display: block; }
  .tiles-scroll-hint { display: block; }
}

@media (min-width: 761px) {
  .page-shell { padding: 2.75rem 1.5rem 4rem; }
  h1 { font-size: clamp(2.2rem, 5vw, 4.3rem); }
  .game-shell { padding: 1.5rem 1rem 3rem; }
  .game-heading { align-items: end; flex-direction: row; justify-content: space-between; }
  .game-heading-actions { width: auto; }
  .game-heading-actions .button { flex: 0 0 auto; }
  .game-heading h1 { font-size: clamp(1.8rem, 5vw, 3.25rem); }
  .game-frame { min-height: 400px; padding: 1rem; }
  .game-frame embed, .game-frame ruffle-embed { width: 100%; height: 100%; }
  .game-loading { inset: 1rem; }
  .game-meta { align-items: center; flex-direction: row; padding: .9rem 1rem; }
  .reset-button { display: none; }
  .editor-layout { grid-template-columns: minmax(0, 1fr) 270px; gap: 1rem; padding: 1rem; }
  .editor-board { padding: 1rem; }
  .level-sidebar { min-height: 0; padding: 1rem; }
  #sortable { min-height: 0; }
  #sortable li { width: 100%; }
  .preview-panel { padding: 1.25rem; }
  .preview-panel .game-frame { min-height: 400px; }
  .publish-row { align-items: center; flex-direction: row; }
  .publish-row input { min-width: 220px; }
  .error-panel { margin: 8vh auto; padding: 2.5rem; }
}