:root {
  color-scheme: light;
  --ink: #42382b;
  --muted: #766a57;
  --paper: #faf5e9;
  --line: #cbbea5;
  --serif: 'Baskerville', 'Georgia', serif;
  --sans: system-ui, -apple-system, sans-serif;
}

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

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #e7dcc1; color: var(--ink); font: 14px var(--sans); }
button, input, select { font: inherit; }
[hidden] { display: none !important; }

.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.game { position: fixed; inset: 0; isolation: isolate; }
#world { display: block; width: 100%; height: 100%; touch-action: none; }
#world.aim-cursor { cursor: crosshair; }
.world-wash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 37%, #755c341d 100%);
}

.hud-top, .hud-bottom {
  position: absolute;
  z-index: 1;
  left: max(30px, env(safe-area-inset-left));
  right: max(30px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}
.hud-top {
  top: max(27px, env(safe-area-inset-top));
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  justify-items: start;
}
.hud-bottom { bottom: max(24px, env(safe-area-inset-bottom)); align-items: flex-end; }
.wordmark, .presence, .movement-help, .locator, .health, .world-button, .weapon-choice {
  background: #faf4e6ed;
  border: 1px solid #a995735c;
  box-shadow: 0 5px 16px #59472a0d;
}
.wordmark { grid-column: 1; display: flex; align-items: center; gap: 11px; padding: 10px 16px 10px 11px; border-radius: 50px; }
.compass-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #faf2df;
  background: #786043;
  font-size: 20px;
  line-height: 1;
}
h1 { margin: 0; font: 600 25px/1 var(--serif); letter-spacing: -.045em; }
.presence {
  grid-column: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border-radius: 40px;
  color: #524b3c;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.presence-dot { width: 7px; height: 7px; border-radius: 50%; background: #9d7b46; box-shadow: 0 0 0 3px #9d7b4622; }
.presence[data-state='online'] .presence-dot { background: #6f7852; box-shadow: 0 0 0 3px #6f785222; }
.presence[data-state='offline'] .presence-dot { background: #a9624d; box-shadow: 0 0 0 3px #a9624d22; }
.health {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 30px;
}
.health-icon { color: #934f44; font: 16px/1 Georgia, serif; }
.health-track { width: clamp(42px, 7vw, 78px); height: 6px; background: #e4d5bd; border-radius: 8px; overflow: hidden; }
.health-track span { display: block; width: 100%; height: 100%; background: #9d6155; transform-origin: left; transition: transform 120ms ease-out; }
.health-value { min-width: 3ch; color: #66483d; text-align: right; font: 650 10px/1 var(--sans); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .health-track span { transition: none; } }
.movement-help { padding: 9px 12px; border-radius: 10px; color: #594e3d; font-size: 11px; }
.keyboard-help { display: flex; gap: 4px; align-items: center; }
.keyboard-help span { margin-left: 4px; }
kbd {
  display: grid;
  min-width: 21px;
  height: 21px;
  padding: 0 3px;
  place-items: center;
  border: 1px solid #c8b89a;
  border-bottom-width: 2px;
  border-radius: 4px;
  color: #514432;
  background: #fffbef;
  font: 600 10px/1 var(--sans);
}
.touch-help { display: none; }
.locator { display: grid; justify-items: center; padding: 2px 6px 9px; border-radius: 13px; }
.locator canvas { display: block; }
.locator output { color: #665a47; font: 10px/1 ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.map-open { display: block; padding: 0; border: 0; border-radius: 9px; color: inherit; background: transparent; cursor: pointer; pointer-events: auto; touch-action: manipulation; }
.map-open:hover { background: #e8dac0; }
.map-dialog { width: min(690px, calc(100% - 24px)); padding: 18px; overflow-y: auto; overscroll-behavior: contain; }
.map-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.map-header h2 { font-size: 30px; text-align: left; }
.map-header p { margin: 5px 0 12px; color: var(--muted); font-size: 12px; }
.map-close { flex: none; width: 44px; height: 44px; border: 1px solid #d9caad; border-radius: 50%; background: #f5ebd7; color: #64523b; font-size: 25px; cursor: pointer; }
#area-map { display: block; width: min(100%, calc(100dvh - 175px)); height: auto; margin: auto; border: 1px solid #bba985; border-radius: 12px; background: #eee0bf; }
.map-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin-top: 10px; color: #594e3d; font-size: 12px; }
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend i { width: 10px; height: 10px; border-radius: 50%; background: #40392b; }
.map-legend .map-player { background: #4d6d99; }
.map-legend .map-enemy { background: #a84d41; }
.map-legend .map-building { border-radius: 2px; background: #9c7453; }
.stick {
  position: absolute;
  z-index: 2;
  width: 106px;
  height: 106px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  border: 1px solid #65523466;
  border-radius: 50%;
  background: #faf2df44;
}
.stick span { width: 37px; height: 37px; border: 1px solid #6150357a; border-radius: 50%; background: #f6ebd6d9; }

dialog {
  width: min(406px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 28px 36px 35px;
  border: 1px solid #c5b694;
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px #54432244, 0 4px 18px #5543241a, inset 0 0 0 4px #fffaf158;
}
dialog::backdrop { background: #6d583435; }
.portrait {
  width: 104px;
  height: 77px;
  margin: 0 auto 9px;
  border: 1px solid #d8c6a3;
  border-radius: 45% 55% 52% 48% / 55% 48% 52% 45%;
  background: #f0e5ce;
  overflow: hidden;
}
.portrait canvas { display: block; width: 100%; height: 100%; }
dialog h2 { margin: 0; text-align: center; font: 500 44px/.98 var(--serif); letter-spacing: -.05em; }
.join-description { margin: 12px 0 23px; text-align: center; color: var(--muted); font-size: 13px; }
.field-label { display: block; margin-bottom: 6px; font-weight: 650; font-size: 12px; }
#join-form input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #c6b693;
  border-radius: 8px;
  background: #fffcf4;
  color: var(--ink);
  font-size: 16px;
  outline: none;
}
#join-form input::placeholder { color: #857860; }
#join-form input:focus-visible { outline: 2px solid #927346; outline-offset: 2px; }
.form-error { margin: 8px 0 0; color: #8b4030; font-size: 12px; }
#join-form button, .appearance-save {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  margin-top: 13px;
  padding: 12px 15px;
  border: 1px solid #59472e;
  border-radius: 8px;
  background: #6a5537;
  color: #fff8e9;
  cursor: pointer;
  font-weight: 650;
}
#join-form button span { font-size: 18px; line-height: 1; }
#join-form button:hover, .appearance-save:hover { background: #57452f; }
button:focus-visible, select:focus-visible { outline: 2px solid #927346; outline-offset: 2px; }
#join-form button:disabled, .appearance-save:disabled { opacity: .65; cursor: wait; }

.world-actions {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-right: auto;
}
.world-button, .weapon-choice {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 11px;
  border-radius: 10px;
  color: #594e3d;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  pointer-events: auto;
  touch-action: manipulation;
}
.world-button { cursor: pointer; }
.world-button:hover:not(:disabled), .weapon-choice:hover { background: #fff8e9; }
.world-button:active:not(:disabled) { background: #e7d9bd; }
.world-button:disabled { color: #766b59; opacity: .74; cursor: default; }
.world-button kbd { padding-inline: 5px; }
#ride-role:not([hidden]) { display: block; margin-top: 2px; font-size: 10px; line-height: 1.15; color: #675b46; }

#attack { touch-action: none; user-select: none; -webkit-touch-callout: none; }
#attack[data-held='true'] { background: #ead8b7; border-color: #96754d; }
.look-button { grid-column: 4; min-height: 40px; border-radius: 30px; }
.look-icon { color: #876943; font-size: 17px; line-height: 1; }
.weapon-choice { position: relative; padding: 0; }
.weapon-choice::after { content: "⌄"; position: absolute; right: 10px; top: 10px; font-size: 15px; pointer-events: none; }
.weapon-choice select {
  width: 100%;
  min-height: 40px;
  appearance: none;
  border: 0;
  border-radius: inherit;
  background: transparent;
  padding: 8px 27px 8px 11px;
  color: inherit;
  font-weight: inherit;
  cursor: pointer;
}
.weapon-choice select:disabled { opacity: .65; cursor: default; }

.appearance { width: min(421px, calc(100% - 24px)); padding: 21px 24px 24px; }
.appearance-header { position: relative; padding: 2px 35px; }
.appearance h2 { font-size: 38px; }
.appearance-close {
  display: grid;
  position: absolute;
  top: -4px;
  right: -4px;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid #d9caad;
  border-radius: 50%;
  background: #f5ebd7;
  color: #64523b;
  font: 24px/1 var(--sans);
  cursor: pointer;
}
.appearance-close:hover { background: #eaddc1; }
.appearance-close:disabled { opacity: .65; cursor: wait; }
.appearance-portrait {
  display: grid;
  position: relative;
  height: 106px;
  margin: 13px 0 9px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #dcc9a7;
  border-radius: 15px;
  background:
    radial-gradient(ellipse at 50% 78%, #d5ba8b65 0 21%, transparent 22%),
    radial-gradient(ellipse at 57% 35%, #faf2de 0 20%, #eaddc169 77%),
    #f1e5cc;
}
.appearance-portrait canvas { display: block; width: 144px; height: 96px; }
.appearance-name-field { margin-top: 10px; }
.appearance-name-field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.appearance-name-field input { padding-block: 8px; }
.appearance-choices { min-width: 0; margin: 10px 0 0; padding: 0; border: 0; }
.appearance-choices legend { margin: 0 0 6px; padding: 0; color: var(--muted); font-size: 12px; font-weight: 650; }
.color-current { margin-left: 4px; color: #8b6e49; font-weight: 500; }
.shape-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.shape-option, .color-option { position: relative; cursor: pointer; }
.shape-face {
  display: grid;
  min-height: 57px;
  align-content: center;
  justify-items: center;
  border: 1px solid #d8c9ad;
  border-radius: 9px;
  background: #f8efdd;
  color: #594e3d;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
}
.shape-face canvas { width: 47px; height: 37px; margin-top: -1px; pointer-events: none; }
.shape-option input:checked + .shape-face { border-color: #9b7547; background: #eee0c3; box-shadow: inset 0 0 0 1px #9b754764; }
.shape-option:hover .shape-face { border-color: #a28964; }
.shape-option input:focus-visible + .shape-face, .color-option input:focus-visible + .color-face { outline: 2px solid #927346; outline-offset: 2px; }
.color-options { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.color-option { display: grid; min-height: 42px; place-items: center; }
.color-face {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid #74644766;
  border-radius: 50%;
  background: var(--swatch);
}
.color-option input:checked + .color-face { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px #96754d; }
.color-option:hover .color-face { border-color: #64533c; }
.color-option:has(input:disabled), .shape-option:has(input:disabled) { cursor: wait; }
.appearance-save { min-height: 44px; justify-content: center; margin-top: 10px; }

@media (max-width: 620px) {
  .hud-top, .hud-bottom { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); gap: 6px; }
  .hud-top { top: max(12px, env(safe-area-inset-top)); grid-template-columns: 1fr auto; }
  .hud-bottom { bottom: max(12px, env(safe-area-inset-bottom)); }
  .wordmark { padding: 7px 11px 7px 7px; gap: 7px; }
  .compass-mark { width: 24px; height: 24px; font-size: 15px; }
  h1 { font-size: 21px; }
  .presence { grid-area: 1 / 2; justify-self: end; padding: 8px 9px; font-size: 11px; }
  .hud-top[data-ready='true'] .presence { grid-row: 2; }
  .health { grid-area: 2 / 1; }
  .look-button { grid-area: 1 / 2; min-height: 38px; }
  .locator { padding: 1px 3px 7px; }
  .locator canvas { width: 84px; height: auto; }
  dialog { padding: 22px 25px 26px; }
  dialog h2 { font-size: 38px; }
  .appearance { padding: 16px 16px 18px; }
  .appearance h2 { font-size: 34px; }
}

@media (max-width: 860px) and (pointer: fine) {
  .movement-help { position: absolute; left: 0; bottom: calc(100% + 8px); }
}
@media (pointer: coarse), (max-width: 555px) {
  /* Leave the left side of the playfield clear for the movement stick. */
  .hud-bottom { align-items: flex-end; }
  .movement-help { max-width: 43%; padding: 7px 9px; line-height: 1.3; }
  .locator { position: fixed; top: max(103px, calc(env(safe-area-inset-top) + 91px)); right: max(12px, env(safe-area-inset-right)); display: grid; padding: 2px 4px 5px; }
  .locator canvas { width: 68px; height: auto; }
  .world-actions {
    position: absolute;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(76px, auto));
    justify-items: stretch;
    gap: 8px;
  }
  .world-actions > button, .weapon-choice select { min-height: 54px; }
  .world-actions > button { font-size: 13px; }
  .weapon-choice select { font-size: 16px; }
  .weapon-choice { grid-area: 1 / 1; }
  #interact { grid-area: 1 / 2; }
  #interact:disabled { visibility: hidden; }
  #attack { grid-area: 2 / 1; }
  #jump { grid-area: 2 / 2; }
}
@media (pointer: coarse) {
  .keyboard-help { display: none; }
  .touch-help { display: inline; }
  .world-button kbd { display: none; }
  .look-button { min-height: 44px; }
  .appearance-name-field input { font-size: 16px; }
  .appearance { overflow-y: auto; overscroll-behavior: contain; }
}
@media (max-width: 555px) and (pointer: fine) {
  .movement-help { display: none; }
}
@media (pointer: coarse) and (max-height: 500px) {
  .hud-top { top: max(8px, env(safe-area-inset-top)); }
  .hud-top[data-ready='true'] .wordmark { display: none; }
  .hud-top[data-ready='true'] .health { grid-area: 1 / 1; }
  .hud-top[data-ready='true'] .presence { grid-row: 2; }
  .hud-bottom { bottom: max(8px, env(safe-area-inset-bottom)); }
  .world-actions > button, .weapon-choice select { min-height: 48px; }
  .locator { top: max(8px, env(safe-area-inset-top)); left: 50%; right: auto; transform: translateX(-50%); }
  .map-dialog { padding: 12px; }
  .map-header h2 { font-size: 24px; }
  #area-map { width: min(100%, calc(100dvh - 135px)); }
}

.region-name {
  max-width: 116px;
  padding: 0 2px 4px;
  text-align: center;
  color: #544933;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.1;
}
@media (max-width: 620px) { .region-name { max-width: 84px; font-size: 10px; } }
