/* The website looks like the game's UI: the same 9-slice pixel art sprites
   (assets/ui, copied from the game by the exporter), the same colors
   (UIStyling.cs) and the same pixel font.
   -> --px is one art pixel on screen. sprites are always scaled by whole
      numbers and never smoothed, so they stay crisp.
   -> 9-slice = CSS border-image: the corners keep their size, the edges and
      the middle stretch. */

@font-face {
    font-family: "Pixel Operator";
    src: url("../fonts/PixelOperator.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "Pixel Operator";
    src: url("../fonts/PixelOperator-Bold.ttf") format("truetype");
    font-weight: 700;
    font-display: swap;
}

:root {
    --px: 3px;
    --sprite-scale: 3;

    /* the game's colors */
    --text: #4a2511;
    --title: #5b2b0f;
    --muted: #8a5a35;
    --button-text: #3b1f0e;
    --selected: #fbe6b8;
    --hover: #f8dcaa;
    --line: #b0763d;
    --track: #6b3412;
    --good: #3f7d20;
    --bad: #b3261e;
    --gold: #9a5b00;
    --parchment: #f6d9a4;
    --outline: #3b1f0e;
    /* the sea around the island */
    --sea: #3a7bbd;
    --sea-dark: #2f69a6;
    --foam: #6ea7dc;
}

@media (max-width: 800px) {
    :root {
        --px: 2px;
        --sprite-scale: 2;
    }
}

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

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: "Pixel Operator", monospace;
    font-size: 16px;
    line-height: 24px;
    color: var(--text);
    /* the sea, with little pixel waves (a tiny pattern drawn right here) */
    background-color: var(--sea);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='48' shape-rendering='crispEdges'%3E%3Cg fill='%236ea7dc'%3E%3Crect x='6' y='10' width='6' height='2'/%3E%3Crect x='12' y='8' width='6' height='2'/%3E%3Crect x='38' y='34' width='6' height='2'/%3E%3Crect x='44' y='32' width='6' height='2'/%3E%3C/g%3E%3Cg fill='%232f69a6'%3E%3Crect x='26' y='20' width='10' height='2'/%3E%3Crect x='52' y='44' width='8' height='2'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 192px 144px;
    background-repeat: repeat;
    image-rendering: pixelated;
    -webkit-font-smoothing: none;
    font-smooth: never;
}

img {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

a {
    color: var(--title);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}
a:hover {
    color: var(--gold);
}

h1, h2, h3, h4 {
    color: var(--title);
    font-weight: 700;
    margin: 0 0 16px;
}
h1 {
    font-size: 32px;
    line-height: 40px;
}
h2 {
    font-size: 32px;
    line-height: 40px;
}
h3 {
    font-size: 16px;
    line-height: 24px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
p {
    margin: 0 0 16px;
}
.muted {
    color: var(--muted);
}
.good {
    color: var(--good);
}
.bad {
    color: var(--bad);
}
.gold {
    color: var(--gold);
}
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* 9-slice pieces ////////////////////////////////////////////////////////// */

/* wooden frame with parchment inside: windows, cards */
.panel {
    border: calc(7 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Frame.png") 7 fill / calc(7 * var(--px)) stretch;
    padding: calc(3 * var(--px)) calc(4 * var(--px));
    image-rendering: pixelated;
}

/* the same frame with nothing in the middle, around pictures */
.frame {
    border: calc(7 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Frame.png") 7 / calc(7 * var(--px)) stretch;
    image-rendering: pixelated;
}

/* sunken box: text fields, info boxes */
.inset {
    border: calc(2 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Inset.png") 2 fill / calc(2 * var(--px)) stretch;
    padding: 4px 8px;
    image-rendering: pixelated;
}

/* item slot */
.slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: calc(64px + 8 * var(--px));
    height: calc(64px + 8 * var(--px));
    border: calc(3 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Slot.png") 3 fill / calc(3 * var(--px)) stretch;
    image-rendering: pixelated;
    vertical-align: middle;
}
a:hover > .slot,
.slot:hover {
    border-image-source: url("../ui/PixelUI_SlotHover.png");
}
.slot img:not(.icon) {
    /* sprites: 32 pixels at exactly 2x; tall sprites keep their shape */
    width: auto;
    height: 64px;
}
/* item and skill icons get their size from the page: a whole multiple of
   their pixels (View::icon), so they stay crisp */
/* only icon slots: creature sprites in the same lists get slot-sm too, but
   keep their own size (.sprite) */
.slot.slot-sm {
    /* room for the 40x40 icons */
    width: calc(40px + 8 * var(--px));
    height: calc(40px + 8 * var(--px));
}
.slot.slot-sm img:not(.icon) {
    width: auto;
    height: 32px;
}

/* white capsule with a black outline, like item amounts in the game */
.tag {
    display: inline-block;
    border: 6px solid transparent;
    border-image: url("../ui/PixelUI_AmountCapsule.png") 3 fill / 6px stretch;
    padding: 0 4px;
    line-height: 16px;
    color: #000;
    font-weight: 700;
    white-space: nowrap;
    image-rendering: pixelated;
    vertical-align: middle;
}

/* raised wooden button */
.btn {
    display: inline-block;
    border: calc(4 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Button.png") 4 fill / calc(4 * var(--px)) stretch;
    padding: 2px 12px;
    font: inherit;
    font-weight: 700;
    color: var(--button-text);
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    background: none;
    image-rendering: pixelated;
}
.btn:hover {
    border-image-source: url("../ui/PixelUI_ButtonHover.png");
    color: var(--button-text);
}
.btn:active,
.btn.is-active {
    border-image-source: url("../ui/PixelUI_ButtonPressed.png");
}
.btn:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 2px dashed var(--outline);
    outline-offset: 2px;
}
.btn[disabled] {
    border-image-source: url("../ui/PixelUI_ButtonDisabled.png");
    color: #5e4a38;
    cursor: default;
}
.btn-big {
    padding: 6px 24px;
    font-size: 32px;
    line-height: 40px;
}
.btn-small {
    border-width: calc(2 * 4px);
    border-image-width: 8px;
    padding: 0 8px;
}

/* page layout ///////////////////////////////////////////////////////////// */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

.site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin-bottom: 16px;
}
.site-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 32px;
    line-height: 40px;
    text-decoration: none;
    color: var(--title);
}
.site-title .sprite {
    --sprite-scale: 2;
}
.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
    align-items: center;
}
.site-nav form {
    margin: 0;
}

.site-footer {
    margin-top: 24px;
    text-align: center;
    color: var(--muted);
}
.site-footer p {
    margin: 0;
}

.flash {
    margin-bottom: 16px;
    font-weight: 700;
}
.flash-good {
    color: var(--good);
}
.flash-bad {
    color: var(--bad);
}

.stack > * + * {
    margin-top: 16px;
}

.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.columns {
    display: grid;
    gap: 16px;
    grid-template-columns: 2fr 1fr;
    align-items: start;
}
/* let wide tables scroll inside their column instead of widening the page */
.columns > *,
.grid > * {
    min-width: 0;
}
@media (max-width: 900px) {
    .columns {
        grid-template-columns: 1fr;
    }
}

.separator {
    height: 2px;
    margin: 16px 0;
    border: 0;
    background: var(--line);
}

/* sprites from the game (CSS animation, no canvas) //////////////////////// */
/* a walk cycle is one image with all frames side by side. the box shows one
   frame; the image slides by one frame at a time. */
.sprite {
    display: inline-block;
    position: relative;
    overflow: hidden;
    flex: none;
    vertical-align: bottom;
}
.sprite img {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: auto;
}
.sprite-32x32 {
    width: calc(32px * var(--sprite-scale));
    height: calc(32px * var(--sprite-scale));
}
.sprite-16x32 {
    width: calc(16px * var(--sprite-scale));
    height: calc(32px * var(--sprite-scale));
}
.sprite-frames-2 img { animation: walk 0.5s steps(2) infinite; }
.sprite-frames-3 img { animation: walk 0.6s steps(3) infinite; }
.sprite-frames-4 img { animation: walk 0.8s steps(4) infinite; }
.sprite-frames-6 img { animation: walk 0.9s steps(6) infinite; }
.sprite-frames-8 img { animation: walk 1.0s steps(8) infinite; }
@keyframes walk {
    from { transform: translateX(0); }
    to   { transform: translateX(-100%); }
}
.sprite-lg {
    --sprite-scale: 4;
}
/* smaller in lists and tables */
.table .sprite,
.entry-list .sprite {
    --sprite-scale: 2;
}
@media (prefers-reduced-motion: reduce) {
    .sprite img {
        animation: none !important;
    }
}

/* landing page //////////////////////////////////////////////////////////// */

.hero {
    position: relative;
    min-height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    /* a view of the island, rendered from the game at 1 pixel = 1 pixel,
       shown at exactly 2x */
    background: url("../game/world/hero.png") center / 1280px 600px no-repeat, #7cc443;
    /* only inside the frame: the frame's rounded corners are see-through,
       and the picture must not show in them */
    background-clip: padding-box;
    background-origin: padding-box;
    overflow: hidden;
}
.hero-card {
    max-width: 640px;
    text-align: center;
}
.hero-card h1 {
    font-size: 64px;
    line-height: 72px;
}
.hero-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
}
.hero-parade {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    display: flex;
    justify-content: center;
    gap: 24px;
    pointer-events: none;
}
@media (max-width: 800px) {
    .hero {
        min-height: 480px;
        background-size: 960px 450px;
    }
    .hero-card h1 {
        font-size: 32px;
        line-height: 40px;
    }
    .hero-parade {
        display: none;
    }
}

.feature-picture {
    display: block;
    width: 100%;
    height: auto;
    border: calc(2 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Inset.png") 2 fill / calc(2 * var(--px)) stretch;
}

.class-card {
    display: flex;
    gap: 16px;
    align-items: center;
}
.class-card .stats-wrap {
    flex: 1;
}
.grid-wide {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}
.columns-even {
    grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) {
    .columns-even {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 500px) {
    .grid-wide {
        grid-template-columns: 1fr;
    }
}

.creature-row {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    align-items: flex-end;
}
.creature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
}

/* forms /////////////////////////////////////////////////////////////////// */

.form {
    max-width: 480px;
    margin: 0 auto;
}
.field {
    margin-bottom: 16px;
}
.field label {
    display: block;
    font-weight: 700;
    color: var(--title);
}
.field input[type="email"],
.field input[type="text"],
.field input[type="password"],
.field input[type="search"] {
    display: block;
    width: 100%;
    font: inherit;
    color: var(--text);
    border: calc(2 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Inset.png") 2 fill / calc(2 * var(--px)) stretch;
    background: none;
    padding: 4px 8px;
    image-rendering: pixelated;
}
.field .hint {
    color: var(--muted);
}
.field .error,
.form-error {
    color: var(--bad);
    font-weight: 700;
}
.search-form {
    display: flex;
    gap: 8px;
    align-items: center;
}
.search-form .field {
    flex: 1;
    margin: 0;
}

/* tables and stat lists /////////////////////////////////////////////////// */

.table {
    width: 100%;
    border-collapse: collapse;
}
.table th,
.table td {
    padding: 4px 8px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 2px solid var(--line);
}
.table th {
    color: var(--title);
}
.table tbody tr:hover {
    background: var(--hover);
}
.table .num {
    text-align: right;
}
.table-wrap {
    overflow-x: auto;
}

.stats {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 16px;
    margin: 0;
}
.stats dt {
    color: var(--muted);
}
.stats dd {
    margin: 0;
    font-weight: 700;
}

/* stat tiles, like the game's Character window (templates/wiki/_stats.php):
   a heading between two lines, then two columns of framed tiles with the
   game's 8x8 stat icon, the name on the left and the value on the right */
/* rare loot (25% or less) */
.tag-rare {
    color: #6a2ca0;
}

/* elements (templates/wiki/_elements.php): like the game's Character window,
   one row per element with defense and damage, the two icons below them */
.element-list {
    display: grid;
    gap: 8px;
}
.element-tile,
.element-key {
    display: flex;
    align-items: center;
    gap: 6px;
}
.element-key {
    /* same left edge and icon room as a tile, so the icons sit under the numbers */
    padding: 0 8px;
    border: calc(2 * var(--px)) solid transparent;
}
.element-key-spacer {
    width: 16px;
    flex: none;
}
.element-value {
    flex: 1 1 0;
    text-align: center;
    font-weight: 700;
    white-space: nowrap;
}
.element-value.zero {
    color: var(--muted);
}
.element-value.bad {
    color: #b3261e;
}
/* the digits are centered; the '%' hangs after them */
.element-number {
    position: relative;
}
.element-percent {
    position: absolute;
    left: 100%;
}

/* a dungeon's last boss */
.tag-boss {
    color: #b3261e;
}

.stat-group + .stat-group {
    margin-top: 12px;
}
.stat-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 1em;
    color: var(--title);
}
.stat-heading::before,
.stat-heading::after {
    content: "";
    flex: 1;
    height: calc(1 * var(--px));
    background: var(--line);
}
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.stat-tile {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 4px 8px;
    border: calc(2 * var(--px)) solid transparent;
    border-image: url("../ui/PixelUI_Inset.png") 2 fill / calc(2 * var(--px)) stretch;
}
.stat-icon {
    /* 2 screen pixels per art pixel, crisp */
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
    flex: none;
}
.stat-label {
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-value {
    margin-left: auto;
    font-weight: 700;
    white-space: nowrap;
}

.entry-list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}
/* room above each new part of a page */
.panel > h2:not(:first-child),
article h2 {
    margin-top: 24px;
}
.entry-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.entry-list li + li {
    border-top: 2px solid var(--line);
}

/* wiki //////////////////////////////////////////////////////////////////// */

.breadcrumbs {
    margin-bottom: 8px;
    color: var(--muted);
}
.breadcrumbs a {
    color: var(--muted);
}

.wiki-sections {
    margin-top: 16px;
}
.wiki-sections .section-card {
    display: flex;
    gap: 12px;
    align-items: center;
    text-decoration: none;
}
.section-card .count {
    margin-left: auto;
}

.entry-head {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}
.entry-head h1 {
    margin: 0;
}

.infobox .entry-picture {
    display: flex;
    justify-content: center;
    padding: 8px 0 16px;
}

.wiki-link {
    font-weight: 700;
}

.world-map {
    display: block;
    max-width: 100%;
    height: auto;
}

/* world map hover highlights (assets/js/world-map.js) */
.world-map-frame {
    position: relative;
}
.world-map-frame .world-map {
    width: 100%;
}
.world-map-overlay {
    position: absolute;
    inset: calc(2 * var(--px));
    width: calc(100% - 4 * var(--px));
    height: calc(100% - 4 * var(--px));
    pointer-events: none;
}
.map-area,
.map-marker {
    opacity: 0;
    transition: opacity 0.15s steps(3);
}
/* the whole group is see-through at once, so overlapping circles look like
   one area instead of getting darker where they overlap */
.map-area.is-shown {
    opacity: 0.6;
}
.map-area-edge {
    fill: #5b1d0c;
}
.map-area-fill {
    fill: #e35d2a;
}
.map-area-spot {
    fill: #5b1d0c;
}
.map-marker.is-shown {
    opacity: 1;
}
.map-marker-ring {
    fill: rgba(255, 244, 214, 0.25);
    stroke: #fff4d6;
    stroke-width: 6;
    animation: map-marker-pulse 1.2s steps(4) infinite;
    transform-box: fill-box;
    transform-origin: center;
}
.map-marker-dot {
    fill: #fff4d6;
    stroke: #3b2410;
    stroke-width: 4;
}
@keyframes map-marker-pulse {
    0%   { transform: scale(0.8); }
    50%  { transform: scale(1.15); }
    100% { transform: scale(0.8); }
}
@media (prefers-reduced-motion: reduce) {
    .map-marker-ring {
        animation: none;
    }
}
.map-target {
    cursor: pointer;
}
.map-target.is-shown,
.map-target:focus-visible {
    outline: calc(1 * var(--px)) solid #b85c1e;
    outline-offset: 2px;
}
.world-map-hint {
    margin-top: 8px;
}
/* dungeon entrances: a purple ring instead of the npcs' white one */
.map-marker-dungeon .map-marker-ring {
    fill: rgba(150, 90, 220, 0.3);
    stroke: #c9a6ff;
}
.map-marker-dungeon .map-marker-dot {
    fill: #c9a6ff;
}
/* places on a dungeon map: where you arrive (green) and the exit (gold) */
.map-marker-start .map-marker-ring {
    fill: rgba(90, 200, 90, 0.3);
    stroke: #9cf08c;
}
.map-marker-start .map-marker-dot {
    fill: #9cf08c;
}
.map-marker-exit .map-marker-ring {
    fill: rgba(240, 190, 60, 0.3);
    stroke: #ffd36b;
}
.map-marker-exit .map-marker-dot {
    fill: #ffd36b;
}
/* the collapsible dungeon list (closed on load) */
.dungeon-menu summary {
    cursor: pointer;
    list-style: none;
}
.dungeon-menu summary::-webkit-details-marker {
    display: none;
}
.dungeon-menu summary h3 {
    display: inline-block;
}
.dungeon-menu summary h3::before {
    content: "+";
    display: inline-block;
    width: 1em;
    margin-right: 4px;
}
.dungeon-menu[open] summary h3::before {
    content: "-";
}

/* account ///////////////////////////////////////////////////////////////// */

.character {
    display: flex;
    gap: 16px;
    align-items: center;
}
.status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    background: var(--muted);
    box-shadow: 0 0 0 2px var(--outline);
    vertical-align: 0;
}
.status-dot.is-online {
    background: #5fd141;
}

/* the little heart in the footer */
.pixel-heart {
    display: inline-block;
    width: 14px;
    height: 12px;
    vertical-align: -1px;
}
