:root {
  color-scheme: dark;
  background: radial-gradient(ellipse at 46% 42%, #f0f7f7 4%, #d4e7ec 70%, #b4ccd7 100%);
  color: #fff;
  font-family: system-ui, -apple-system, "PingFang SC", sans-serif;
  --hud-inset: clamp(20px, 3vw, 48px);
  --map-diameter: 148px;
}

* { box-sizing: border-box; }

html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }

#loading-screen {
  position:fixed;inset:0;z-index:10;isolation:isolate;display:grid;align-content:center;
  padding:max(26px,env(safe-area-inset-top)) max(7vw,env(safe-area-inset-right));
  color:#f2dfb6;background:#0a2029 url('./assets/loading-voyage.jpg') 60% 50% / cover no-repeat;
}
#loading-screen[hidden] {display:none}
#loading-screen::before {content:"";position:absolute;z-index:-1;inset:0;background:linear-gradient(90deg,#03172073,transparent 62%)}
#loading-screen::after {content:"";position:absolute;inset:max(13px,env(safe-area-inset-top)) max(13px,env(safe-area-inset-right)) max(13px,env(safe-area-inset-bottom)) max(13px,env(safe-area-inset-left));border:1px solid #cfb57c59;box-shadow:0 0 0 4px #00141c18;pointer-events:none}
.loading-panel {position:relative;width:min(38vw,425px);padding:16px 0;text-shadow:0 2px 12px #00121a}
.loading-course {display:flex;align-items:center;gap:10px;width:95px;color:#d1b178}
.loading-course i {height:1px;background:currentColor;flex:1}
.loading-course i:first-child {flex:0 0 16px}
.loading-course span {font:18px/1 Georgia,serif}
.loading-panel h1 {margin:13px 0 28px;color:#f3dfb3;font:750 clamp(36px,4.3vw,72px)/1.24 "Songti SC","STSong","Noto Serif CJK SC",Georgia,serif;letter-spacing:.09em;white-space:nowrap}
#loading-progress {display:block;width:100%;height:5px;padding:0;border:0;appearance:none;background:#69817b59;accent-color:#e5c182}
#loading-progress::-webkit-progress-bar {background:#69817b59}
#loading-progress::-webkit-progress-value {background:linear-gradient(90deg,#967b49,#e9cd92);transition:width .15s}
#loading-progress::-moz-progress-bar {background:#e9cd92}
.loading-readout {display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin-top:10px}
#loading-status {margin:0;color:#e3ded0;font-size:13px;line-height:1.65}
#loading-value {font:500 13px/1.4 ui-monospace,"SFMono-Regular",monospace;color:#e3c48b}
#loading-retry {margin-top:12px;min-height:44px;padding:6px 18px;border:1px solid #d4be8f;border-radius:1px;background:#ead8b0;color:#163435;font:650 14px/1.3 system-ui,sans-serif;cursor:pointer}
#loading-retry:focus-visible {outline:2px solid #f3d69a;outline-offset:3px}
@media(max-width:650px) and (orientation:portrait) {
  #loading-screen {align-content:end;padding:0 max(32px,env(safe-area-inset-left)) max(8dvh,calc(env(safe-area-inset-bottom) + 20px));background:#071e29}
  #loading-screen::before {background:linear-gradient(180deg,transparent 54%,#071e29 82%),url('./assets/loading-voyage.jpg') 82% top / auto 83% no-repeat}
  .loading-panel {width:100%;padding:0}
  .loading-panel h1 {font-size:clamp(38px,10vw,59px);margin:10px 0 21px}
}
@media(prefers-reduced-motion:reduce) {#loading-progress::-webkit-progress-value {transition:none}}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

#world {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#world.is-dragging { cursor: grabbing; }

#navigation-map {
  position: absolute;
  top: max(var(--hud-inset), env(safe-area-inset-top) + 8px);
  right: max(var(--hud-inset), env(safe-area-inset-right) + 8px);
  width: var(--map-diameter);
  height: var(--map-diameter);
  pointer-events: none;
}

#navigation-map .fish-guide-link {
  display: table;
  margin: 8px auto 0;
  padding: 5px 10px;
  border: 1px solid #ffffff52;
  border-radius: 16px;
  background: #203437cf;
  color: #fff;
  font-family: inherit;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: auto;
}
#navigation-map :is(.fish-guide-link,#rear-route select,#rear-route button):focus-visible {
  outline: 2px solid #f3ddb2;
  outline-offset: 2px;
}
#fish-guide-trigger { cursor: pointer; }
#navigation-map #fish-guide-trigger {
  display: grid;
  place-items: center;
  padding: 0;
  width: 33px;
  height: 32px;
  margin-top: 6px;
  background: #20343789;
}
#navigation-map #fish-guide-trigger:hover { background: #203437df; }

#rear-route {
  display: flex;
  width: max(100%, 130px);
  position: relative;
  right: max(0px, 130px - 100%);
  margin-top: 7px;
  padding: 2px;
  gap: 2px;
  border: 1px solid #b8d2c267;
  border-radius: 8px;
  background: #203437eb;
  pointer-events: auto;
}
#rear-route[hidden] { display: none; }
#rear-route :is(select,button) {
  min-height: 30px;
  border-radius: 5px;
  color: #f4f3e8;
  font: 650 12px/1.2 system-ui, sans-serif;
}
#rear-route select { min-width: 0; flex: 1; border: 0; padding: 2px 4px; background: #243933; }
#rear-route button {
  flex: none;
  border: 1px solid #b8d2c252;
  padding: 2px 7px;
  background: #405951;
  cursor: pointer;
}
#rear-route button:hover { background: #4c685d; }
@media (pointer: coarse) {
  #rear-route :is(select,button) { min-height: 42px; }
  #navigation-map #fish-guide-trigger { width: 44px; height: 44px; }
}

#minimap {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 50%;
  background: rgba(20, 20, 20, .36);
  box-shadow: 0 3px 16px rgba(0, 0, 0, .24);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
}

#minimap:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }

#presence {
  position: absolute;
  top: max(var(--hud-inset), env(safe-area-inset-top) + 8px);
  left: max(var(--hud-inset), env(safe-area-inset-left) + 8px);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 999px;
  background: rgba(21,31,37,.64);
  font: 600 12px/1.25 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(7px);
  pointer-events: none;
}

.presence-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.48);
}

#presence[data-connection="online"] .presence-dot {
  background: #56dcb3;
  box-shadow: 0 0 6px #56dcb36b;
}

#social-chat {
  position: absolute;
  z-index: 1;
  right: max(var(--hud-inset), env(safe-area-inset-right) + 8px);
  bottom: calc(max(var(--hud-inset), env(safe-area-inset-bottom) + 8px) + var(--social-keyboard-inset, 0px));
  display: grid;
  justify-items: end;
  gap: 7px;
  width: min(390px, calc(100% - 2 * var(--hud-inset) - 60px));
  pointer-events: none;
}

#chat-messages {
  display: grid;
  justify-items: end;
  gap: 4px;
  width: calc(100% - 51px);
  max-height: min(36dvh, 210px);
  padding: 0;
  margin: 0 51px 0 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  list-style: none;
}

#chat-messages:empty { display: none; }
#social-chat[data-open="true"] #chat-messages { pointer-events: auto; }
#social-chat[data-open="false"] #chat-messages { overflow: hidden; }

.chat-message {
  max-width: 100%;
  padding: 5px 9px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 13px;
  color: #fafcfb;
  background: rgba(21,31,37,.76);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-message-name { color: #b5ded1; font-weight: 650; }
#chat-feedback { margin: 0; padding: 4px 8px; border-radius: 5px; background: #202a30ee; font-size: 12px; }

.chat-controls {
  display: flex;
  align-items: stretch;
  justify-content: end;
  gap: 7px;
  width: 100%;
}

#chat-form {
  display: flex;
  flex: 1 1 auto;
  align-items: stretch;
  min-width: 0;
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 9px;
  background: rgba(21,31,37,.93);
  pointer-events: auto;
}

#chat-form[hidden] { display: none; }
#chat-input, #sail-nickname {
  min-width: 0;
  min-height: 42px;
  color: #fff;
  font: 16px/1.2 system-ui, sans-serif;
}

#chat-input { flex: 1 1 0; width: 0; padding: 6px 8px; border: 0; background: transparent; }
#chat-input::placeholder { color: #aebcb9; }

.chat-send, #chat-trigger {
  border: 0;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-send {
  padding: 0 9px;
  border-left: 1px solid rgba(255,255,255,.16);
  border-radius: 0 8px 8px 0;
  background: transparent;
  white-space: nowrap;
  font: 600 13px/1.2 system-ui, sans-serif;
}

#chat-trigger {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.47);
  border-radius: 999px;
  background: rgba(21,31,37,.76);
  backdrop-filter: blur(7px);
  pointer-events: auto;
}

#chat-trigger svg { stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#chat-trigger circle { stroke: none; fill: currentColor; }
#chat-trigger:active, .chat-send:active { background: rgba(46,66,66,.95); }
@media (hover: hover) {
  #chat-trigger:hover, .chat-send:hover { background: rgba(46,66,66,.95); }
}
#chat-trigger:focus-visible, #chat-input:focus-visible, .chat-send:focus-visible,
#sail-profile :is(input,button):focus-visible { outline: 2px solid #d1eedf; outline-offset: 2px; }
#chat-input:focus-visible { outline-offset: -2px; border-radius: 8px 0 0 8px; }

#sail-profile {
  width: min(340px, calc(100% - 34px));
  padding: 22px;
  border: 1px solid rgba(216,237,225,.42);
  border-radius: 13px;
  color: #fff;
  background: #202b31;
  box-shadow: 0 12px 42px #08212a8a;
}

#sail-profile::backdrop { background: #08161f83; backdrop-filter: blur(4px); }
#sail-profile-form { display: grid; gap: 12px; }
#sail-profile-title { margin: 0 0 2px; font-size: 20px; font-weight: 650; }
#sail-nickname { padding: 8px 10px; border: 1px solid #d7f1e257; border-radius: 6px; background: #152129; }
#sail-profile-error { margin: 0; color: #ffcfbc; font-size: 13px; }
#sail-profile button {
  min-height: 42px;
  padding: 7px 14px;
  border: 0;
  border-radius: 6px;
  color: #18292a;
  background: #e0eee6;
  font: 650 14px/1.2 system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.readings {
  position: absolute;
  bottom: max(var(--hud-inset), env(safe-area-inset-bottom) + 8px);
  left: max(var(--hud-inset), env(safe-area-inset-left) + 8px);
  display: grid;
  gap: 4px;
  color: rgba(255, 255, 255, .94);
  font-size: 14px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
  line-height: 1.35;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8), 0 0 12px rgba(0, 0, 0, .36);
  pointer-events: none;
}

#storm-sound:not([hidden]) {
  pointer-events:auto; justify-self:start; min-height:34px; padding:4px 10px;
  border:1px solid #b4c7c17a; border-radius:6px; background:#14323bdf; color:#f2e6c9;
  font:inherit; font-size:12px; letter-spacing:.01em; cursor:pointer;
}
#storm-sound:focus-visible { outline:2px solid #f3ddb2; outline-offset:2px }
@media(pointer:coarse){#storm-sound:not([hidden]){min-height:44px}}
#world-state {
  position: absolute;
  pointer-events: none;
  inset: 50% auto auto 50%;
  width: max-content;
  max-width: min(390px, calc(100% - 40px));
  translate: -50% -50%;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, .94);
  text-align: center;
  text-shadow: 0 1px 5px #000;
}

#world-state:empty, [hidden] { display: none; }
#world-state .notice-guide {
  border: 0;
  padding: 3px 1px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  pointer-events: auto;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-shadow: inherit;
}

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

@media (max-width: 680px), (max-height: 520px) {
  :root { --hud-inset: 17px; --map-diameter: 96px; }
  .readings { font-size: 13px; }
}

/* A tricolor pennant and the sender stay attached to each entry in the ship's log. */
#social-chat {width:min(358px,calc(100% - max(var(--hud-inset),env(safe-area-inset-left) + 8px) - max(var(--hud-inset),env(safe-area-inset-right) + 8px)));min-width:0;grid-template-columns:minmax(0,1fr);gap:5px}
#social-chat[data-open=true] {z-index:4;padding:8px;border:1px solid #b09a68;background:#143136f5;box-shadow:inset 0 0 0 3px #244247,0 4px 16px #03182060;border-radius:4px}
#chat-messages {display:flex;flex-direction:column;align-items:flex-start;width:100%;min-width:0;margin:0;overflow-x:hidden;max-height:min(38dvh,258px,calc(var(--chat-visible-height,100dvh) - 86px));gap:7px;padding:3px 6px 5px;scrollbar-color:#a28e65 transparent}
#social-chat[data-open=false] #chat-messages {align-items:flex-end;padding:3px 5px 4px;max-height:none;overflow:visible}
.chat-message {
  --note-paper:#eee4ca;--note-border:#b49d70;--note-ink:#203c39;--note-meta:#655d49;
  position:relative;flex:0 0 auto;width:fit-content;max-width:100%;min-width:0;padding:6px 10px 7px;
  border:1px solid var(--note-border);border-radius:2px;background:var(--note-paper);
  color:var(--note-ink);font-size:13px;line-height:1.5;overflow-wrap:anywhere;
}
.chat-message[data-self=true] {--note-paper:#29484a;--note-border:#9a906b;--note-ink:#f1ead8;--note-meta:#dcc795;align-self:flex-end}
.chat-message::after {content:"";position:absolute;left:-4px;bottom:7px;width:5px;height:5px;background:var(--note-paper);border:solid var(--note-border);border-width:0 0 1px 1px;transform:rotate(45deg)}
.chat-message[data-self=true]::after {left:auto;right:-4px;transform:rotate(225deg)}
.chat-sender {display:flex;align-items:center;gap:5px;min-width:0;color:var(--note-meta);font-size:10px}
.chat-message-name {overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:18ch;color:inherit;font-weight:700}
.chat-sender time {font:500 9px/1.4 ui-monospace,monospace;color:inherit}
.chat-flag {display:inline-block;flex:none;position:relative;width:12px;height:9px;background:linear-gradient(90deg,#7b442f 47%,#e9bf76 47%);clip-path:polygon(0 0,100% 0,77% 50%,100% 100%,0 100%)}
.chat-flag[data-pattern="1"] {background:linear-gradient(45deg,#385f60 43%,#dcc795 43% 59%,#385f60 59%)}
.chat-flag[data-pattern="2"] {background:linear-gradient(#7e4131 50%,#e1b477 50%)}
.chat-flag[data-pattern="3"] {background:conic-gradient(#ead494 25%,#406464 25% 50%,#ead494 50% 75%,#406464 75%)}
.chat-message[data-self=true] .chat-flag {filter:brightness(1.13)}
.chat-message-body {display:block;word-break:normal;overflow-wrap:anywhere}
#social-chat[data-open=false] .chat-message {display:block;max-width:100%;padding:6px 10px;cursor:pointer;pointer-events:auto;touch-action:manipulation}
#social-chat[data-open=false] .chat-sender {display:inline;color:var(--note-meta);font-size:12px}
#social-chat[data-open=false] .chat-message-name {white-space:normal;overflow-wrap:anywhere}
#social-chat[data-open=false] .chat-message-name::after {content:" · ";color:var(--note-meta)}
#social-chat[data-open=false] :is(time,.chat-flag) {display:none}
#social-chat[data-open=false] .chat-message-body {display:inline;white-space:pre-wrap;overflow-wrap:anywhere}
#social-chat[data-open=true] .chat-message-body {white-space:pre-wrap}
#social-chat[data-open=true] .chat-message {min-width:min(90px,100%)}
#chat-feedback {justify-self:stretch;border-radius:1px;background:#eadbc0;color:#813f2b}
#chat-form {border:1px solid #b19a69;border-radius:2px;background:#ece2c9}
#chat-input {color:#183f40}
#chat-input::placeholder {color:#64695b}
#chat-input:focus-visible {outline-color:#a86c36;outline-offset:-3px;border-radius:0}
.chat-send {min-width:46px;border-left:1px solid #a99363;border-radius:0;background:#d9c69b;color:#24433c}
.chat-send:hover,.chat-send:active {background:#e7d4a7;color:#183a36}
#chat-trigger,#presence,#navigation-map #fish-guide-trigger {
  border:1px solid #b49e6e;background:#18363be8;color:#f2e4be;box-shadow:inset 0 0 0 2px #29454b,0 2px 8px #0a242e38;
}
#chat-trigger {border-radius:50% 50% 50% 6px}
#chat-trigger:hover,#navigation-map #fish-guide-trigger:hover {background:#2c4b49}
#social-chat[data-open=true] #chat-trigger {border-radius:2px}
#social-chat[data-open=true] #chat-trigger svg {display:none}
#social-chat[data-open=true] #chat-trigger::after {content:"×";font:27px/1 Georgia,serif}
#presence {border-radius:3px}
#minimap {border-color:#d4c193;box-shadow:0 0 0 2px #183638,0 0 0 3px #b29d6c,0 3px 12px #14272d66}
#rear-route {border-color:#aa9669;border-radius:2px;background:#1d3c40}
#rear-route :is(select,button) {border-radius:1px}
#sail-profile {width:min(340px,calc(100% - 34px));padding:26px;border:5px solid #1b393c;outline:1px solid #b59a67;border-radius:2px;background:repeating-linear-gradient(14deg,#95764405 0 1px,transparent 1px 4px),#e9dec2;color:#20403c;box-shadow:inset 0 0 0 1px #ad9567,0 12px 42px #08212a8a;color-scheme:light}
#sail-profile-form {gap:8px}
#sail-profile-title {margin:0 0 7px;padding-bottom:10px;border-bottom:3px double #b29b72;font:750 29px/1.3 "Songti SC","Noto Serif CJK SC",Georgia,serif;letter-spacing:.06em}
#sail-profile label {color:#5b5a4a;font-size:12px}
#sail-nickname {margin:0 0 5px;border-color:#9b916f;border-radius:1px;background:#f8f0dc;color:#1a393a}
#sail-profile button {min-height:44px;border:1px solid #bca474;border-radius:2px;background:#254748;color:#f5e4bf}
#sail-profile-error {color:#833b2b}
#sail-profile :is(input,button):focus-visible {outline-color:#a35f35}
@media (max-width:680px) {
  #social-chat[data-open=false] #chat-messages {margin-bottom:42px}
  #app:has(#angling:not([hidden]):not([data-phase=idle])) #social-chat[data-open=false] #chat-messages {margin-bottom:99px}
}


#social-chat[data-open=true] .chat-message {
  display:grid;grid-template-columns:30px minmax(0,1fr);column-gap:8px;align-items:center;
  background:repeating-linear-gradient(24deg,#86683208 0 1px,transparent 1px 4px),var(--note-paper);
  box-shadow:inset 0 0 0 2px var(--note-paper),inset 0 0 0 3px #b29c7157,0 1px 2px #0a272d33;
}
.chat-message::before {
  content:"";grid-row:span 2;align-self:center;box-sizing:border-box;flex:none;
  width:29px;height:29px;border:2px solid #b49864;border-radius:50%;
  box-shadow:0 0 0 1px #655638,inset 0 0 0 1px #e4d39c;
  background:#ccb78d url('./assets/port-activities.jpg') 0 0 / 400% 200%;
}
.chat-message[data-self=true]::before {background-position:33.3333% 0}
#social-chat[data-open=false] .chat-message::before {display:none}

#navigation-map #helm-view {
  position:absolute;right:calc(50% + 2px);top:calc(100% + 6px);margin-right:1px;
  min-width:42px;height:32px;border:1px solid #baa78088;border-radius:11px;
  background:#263e3de8;color:#efdfbb;font:650 12px/1 system-ui;pointer-events:auto;cursor:pointer;
}
body[data-view="ship"] #navigation-map:has(#helm-view:not([hidden])) #fish-guide-trigger {margin-inline-start:calc(50% + 3px)}
#navigation-map #helm-view[aria-pressed=true] {color:#302d20;background:#e4c884}
#navigation-map #helm-view:focus-visible {outline:2px solid #f3ddb2;outline-offset:2px}
@media(pointer:coarse), (max-width:540px){#navigation-map #helm-view{min-width:44px;height:44px}
  #navigation-map #fish-guide-trigger{width:44px;height:44px}}

@media (orientation:landscape) and (max-height:450px) {
  #social-chat[data-open=false] #chat-messages {max-width:min(40vw,264px)}
  #social-chat[data-open=false] .chat-message {
    display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;padding-block:0;line-height:1.65;
  }
}

@media (max-width:400px) {
  #app:has(#angling:not([hidden]):not([data-phase=idle])) #social-chat[data-open=false] {
    bottom:calc(max(var(--hud-inset),env(safe-area-inset-bottom) + 8px) + 48px)
  }
  #app:has(#angling:not([hidden]):not([data-phase=idle])) #social-chat[data-open=false] #chat-messages {margin-bottom:51px}
}
