* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #124b4a;
  font:
    600 15px -apple-system,
    BlinkMacSystemFont,
    Roboto,
    sans-serif;
  color: #fcf3cf;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button,
input {
  font: inherit;
}
button {
  cursor: pointer;
  color: inherit;
}
button:active {
  transform: translateY(2px);
}
#world {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
header,
footer,
aside {
  position: fixed;
  pointer-events: none;
}
header {
  top: max(13px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
button {
  pointer-events: auto;
}
#profile,
.round,
#resources,
#mapBtn {
  background: linear-gradient(140deg, #294941, #17382e);
  border: 2px solid #bda16e;
  box-shadow:
    0 3px 0 #102924,
    0 5px 14px #14332145;
}
#profile {
  display: flex;
  align-items: center;
  text-align: left;
  border-radius: 13px;
  padding: 4px 11px 5px 3px;
  height: 54px;
  gap: 6px;
}
#profile img {
  width: 42px;
  height: 44px;
  object-fit: contain;
}
#profile span {
  display: grid;
  gap: 2px;
}
small,
#mode,
#guide,
#clock {
  font-size: 10px;
  letter-spacing: 1.1px;
}
#mode {
  color: #e5c584;
}
#profile b {
  font-family: Georgia, serif;
  font-size: 16px;
}
#profile i {
  background: #182820;
  border-radius: 5px;
  height: 4px;
  overflow: hidden;
}
#profile em {
  display: block;
  height: 100%;
  background: #8ede83;
}
#resources {
  border-width: 1px;
  border-radius: 12px;
  display: flex;
  gap: 13px;
  padding: 8px 12px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
#resources span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.gold,
.log {
  display: inline-block;
  width: 15px;
  height: 16px;
}
.gold {
  border-radius: 50%;
  background: #fdbd42;
  border: 2px solid #ffe497;
  box-shadow:
    inset -2px -2px #cc7c22,
    1px 2px #ae742f;
}
.log {
  width: 18px;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(0deg, #73452c, #cc935e);
  border-left: 5px solid #eabb82;
  transform: rotate(-28deg);
}
.grain {
  font-size: 22px;
  color: #eacc69;
  line-height: 15px;
}
aside {
  right: max(14px, env(safe-area-inset-right));
  top: max(14px, env(safe-area-inset-top));
  display: grid;
  justify-items: center;
  gap: 5px;
}
#mapBtn {
  border-radius: 50%;
  padding: 2px;
  width: 67px;
  height: 67px;
  overflow: hidden;
}
#mini {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
#clock,
#guide,
#message {
  background: #183a32df;
  border: 1px solid #d3b57566;
  border-radius: 12px;
  padding: 6px 10px;
}
#clock {
  font-size: 10px;
  letter-spacing: 0.2px;
}
footer {
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: end;
  gap: 10px;
}
.round {
  border-radius: 15px;
  font: 30px Georgia;
  width: 50px;
  height: 48px;
}
#stick {
  width: clamp(108px, 31vmin, 138px);
  height: clamp(108px, 31vmin, 138px);
  flex-shrink: 0;
  border: 2px solid #ccb37d;
  border-radius: 50%;
  background: radial-gradient(circle, #21382e85, #294638c4);
  box-shadow: inset 0 2px 7px #17272177, 0 2px 4px #233b2980;
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
#stick span {
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 25%, #f7dc9f, #bf9859 75%);
  border: 2px solid #f4dcaa;
  box-shadow: 0 3px 4px #16291dd0;
  pointer-events: none;
}
#home { position: absolute; bottom: calc(clamp(108px, 31vmin, 138px) + 10px); width: 38px; height: 38px; font-size: 23px; }
#guide {
  max-width: 240px;
  letter-spacing: 0.1px;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px 12px;
  align-self: center;
}
#action,
.primary {
  margin-left: auto;
  min-width: 136px;
  background: linear-gradient(#ffda70, #e8a72b);
  color: #473316;
  border: 2px solid #fff0ae;
  box-shadow:
    0 4px #936727,
    0 5px 12px #2a311e55;
  border-radius: 14px;
  padding: 9px 18px;
  display: grid;
  gap: 2px;
}
#action[hidden] {
  display: none;
}
#action span {
  font:
    bold 19px Georgia,
    serif;
}
#action small {
  font-size: 9px;
}
#message {
  position: fixed;
  left: 50%;
  bottom: 87px;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 90%;
  width: max-content;
}
dialog {
  border: 0;
  background: transparent;
  color: #333727;
  padding: 0;
  width: min(450px, 94vw);
  max-height: 85dvh;
  border-radius: 20px;
}
dialog::backdrop {
  background: #0e271f8f;
}
.paper {
  padding: 24px;
  background: linear-gradient(135deg, #fff2ce, #e4d1a2);
  border: 3px solid #93774d;
  border-radius: 19px;
  box-shadow: inset 0 0 0 2px #ffefc5;
}
.paper h2 {
  font: 700 26px Georgia;
  margin: 2px 35px 5px 0;
}
.paper p {
  font-size: 13px;
  line-height: 1.45;
}
.paper button {
  color: #263e32;
}
.paper #close {
  float: right;
  width: 35px;
  height: 35px;
  border: 1px solid #b49c72;
  background: #f7e7bd;
  font-size: 24px;
  border-radius: 10px;
}
.rows {
  display: grid;
  gap: 5px;
}
.rows button,
.paper .opt {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  background: #fff7df;
  border: 1px solid #beaa7e;
  border-radius: 9px;
  padding: 6px 10px;
  min-height: 40px;
  text-align: left;
}
.rows img {
  width: 37px;
  height: 37px;
  object-fit: contain;
}
.rows span {
  flex: 1;
}
.rows small {
  display: block;
  color: #676850;
  font-size: 11px;
  letter-spacing: 0;
}
.rows strong {
  font: 700 15px Georgia;
}
.rows button:disabled {
  opacity: 0.55;
}
.paper input {
  width: 100%;
  margin: 4px 0;
  padding: 9px;
  border: 1px solid #b8a275;
  border-radius: 8px;
}
.paper .primary {
  margin: 9px 0;
  color: #513518;
}
.bigmap {
  display: block;
  width: min(100%, 68dvh);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 14px;
}
@media (max-width: 560px) {
  header {
    flex-direction: column;
    gap: 3px;
  }
  #resources {
    margin: 0;
  }
  #guide {
    max-width: 110px;
    font-size: 10px;
  }
  footer {
    gap: 5px;
  }
  #action {
    min-width: 110px;
    padding: 8px 11px;
  }
}

.looks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 7px 0;
}
.looks button {
  position: relative;
  flex-direction: column;
  gap: 4px;
  padding: 7px 2px 8px;
  border: 2px solid #bba780;
  background: #f5e9c9;
}
.looks img {
  width: 100%;
  height: clamp(60px, 18dvh, 112px);
}
.looks button[aria-pressed="true"] {
  background: #fff6d6;
  border-color: #81601c;
  box-shadow: inset 0 0 0 2px #ecc45e;
}
.looks button[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 4px;
  color: #fff;
  background: #42604b;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
}
.rows .confirm-look {
  justify-content: center;
  background: #f4c559;
  border: 2px solid #9b752a;
  text-align: center;
}
.looks button:focus-visible, .confirm-look:focus-visible {
  outline: 3px solid #245a50;
  outline-offset: 2px;
}

#action { touch-action: none; }

body.waiting header, body.waiting footer, body.waiting aside, body.waiting #world {visibility:hidden}
#connection:not([hidden]) {position:fixed;inset:0;display:grid;place-content:center;text-align:center;padding:24px;background:#183d35;color:#fff4d2;z-index:5}
#action:disabled {opacity:.65}

#title {display:block;max-width:clamp(72px,15vw,170px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.paper .hall-stock {
  width: fit-content;
  padding: 6px 10px;
  margin: 5px 0 8px;
  color: #254638;
  background: #fff5d7;
  border: 1px solid #b79d6b;
  border-radius: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rows input[type="range"] { padding: 0; min-height: 28px; accent-color: #42604b; }
.rows output { display: block; padding: 4px 0; font-variant-numeric: tabular-nums; }
.rows .transfer-hold {
  justify-content: center;
  min-height: 46px;
  background: linear-gradient(to right, #e9bd5a var(--held, 0%), #fff7df var(--held, 0%));
  font-size: 16px;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.island-roster { margin: 10px 0 14px; }
.island-roster h3 { font: 700 16px Georgia,serif; margin: 0 0 4px; }
.island-roster div { display: flex; align-items: center; gap: 9px; border-bottom: 1px solid #cdb68b; padding: 3px 0; }
.island-roster img { width: 47px; height: 47px; object-fit: contain; }
.island-roster b { overflow-wrap: anywhere; }
.island-roster small { margin-left: auto; color: #4b5947; white-space: nowrap; }
.food-icon {width:22px;height:22px;object-fit:contain}
#socialHUD {position:fixed;left:max(12px,env(safe-area-inset-left));top:88px;display:flex;align-items:center;gap:5px}
#socialHUD button {border:1px solid #bdab7c;background:#203e35ed;color:#fff0c0;border-radius:10px;padding:6px 10px;touch-action:none}
#socialHUD .transmitting {background:#9c402d} #speakers {text-shadow:0 1px 3px #132b20}
.waiting #socialHUD {display:none}
#chatLog {max-height:26dvh;min-height:48px;overflow:auto;background:#fff6db;border-radius:8px;padding:6px 9px;user-select:text}
#chatLog p {margin:3px 0;overflow-wrap:anywhere}
#chatLog+form {display:flex;gap:5px}
#chatLog+form input {min-width:0;flex:1} #chatLog+form button {width:auto}
.chat-quick summary {padding:8px 10px;cursor:pointer;font-weight:600}
.chat-quick button {margin-top:4px}
#mentor:not([hidden]) {display:flex;align-items:flex-end;pointer-events:none}
#mentorHome #mentor {position:fixed;bottom:max(8px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);width:clamp(220px,calc(100% - 350px),455px);z-index:1}
#mentor>img {width:clamp(38px,7vw,76px);align-self:flex-end;filter:drop-shadow(0 2px 2px #16282077)}
.mentor-card {flex:1;min-width:0;background:#fff3d2;border:2px solid #8c7446;border-radius:14px 14px 14px 3px;color:#302e22;padding:8px 11px;box-shadow:0 3px 6px #17291d55}
.mentor-heading,.mentor-actions {display:flex;align-items:center;gap:8px}
.mentor-heading b {font:700 15px Georgia,serif;color:#665026}
#mentorStep {margin-left:auto;font-size:11px;color:#695736}
#mentor p {font-size:13px;line-height:1.3;margin:4px 0}
#mentorStatus {display:block;color:#43583e;font-size:12px}
#mentorStatus:empty {display:none}
.mentor-actions {margin-top:3px}
.mentor-actions button {min-height:32px;padding:4px 8px;border:0;background:transparent;border-radius:6px;color:#455440;font:600 12px system-ui;touch-action:manipulation}
#content #mentor {position:static;max-width:100%;margin:4px 0 10px}
#content #mentor>img {width:42px}
#content #mentor .mentor-card {box-shadow:none}
@media(max-width:700px){#mentorHome #mentor>img{width:35px}.mentor-card{padding:6px 8px}}
@media(max-width:520px){#mentorHome #mentor{bottom:calc(clamp(108px,31vmin,138px) + 24px);width:min(88vw,350px)}}
.rows {min-width:0;grid-template-columns:minmax(0,1fr)}
.catalogue {min-width:0;margin:3px 0 11px}
.catalogue-heading {display:flex;align-items:center;gap:6px;margin:0 0 6px}
.catalogue-heading h3 {margin:0 auto 0 0;font:700 19px Georgia,serif}
.rows .catalogue-heading button {display:grid;place-items:center;width:36px;min-height:34px;padding:0;font:700 23px Georgia,serif}
.building-cards {display:flex;overflow-x:auto;gap:10px;scroll-snap-type:x mandatory;overscroll-behavior-x:contain;scrollbar-width:thin;scrollbar-color:#aa8850 transparent;padding:1px 1px 5px;-webkit-overflow-scrolling:touch}
.building-card {position:relative;flex:0 0 min(88%,350px);scroll-snap-align:start;display:grid;grid-template-columns:34% 1fr;grid-template-rows:1fr auto;gap:0 8px;align-items:center;background:#fbf0cf;border:1px solid #a88956;border-radius:13px;overflow:hidden;box-shadow:0 2px 0 #b8a16d}
.building-art {align-self:stretch;display:grid;place-items:center;background:radial-gradient(ellipse at 50% 72%,#b0b777,#dce3ad 74%,#e4e4b9);margin:0}
.rows .building-art img,.building-art canvas {width:96%;height:88px;object-fit:contain;filter:drop-shadow(0 4px 2px #45533135)}
.building-copy {padding:9px 9px 6px 1px;color:#243b2c}
.building-copy h4 {font:700 17px Georgia,serif;margin:0}
.paper .building-copy p {font-size:12px;line-height:1.28;margin:4px 0 6px}
.build-price,.card-bottom {display:flex;align-items:center}
.build-price {gap:4px;color:#5a421e;font-size:12px;flex-wrap:wrap}
.build-price .gold,.build-price .log {width:13px;height:13px;margin:0 1px 0 0;display:inline-block}
.build-price .log {margin-left:7px}
.card-bottom {grid-column:1/-1;justify-content:space-between;padding:4px 7px;background:#f1e3bb;border-top:1px solid #cbbb8d;gap:6px}
.rows .card-bottom button,.inspect-actions button {justify-content:center;width:auto;background:#f0c36b;color:#483219;border:1px solid #a57b35;border-radius:7px;min-height:33px;padding:4px 10px;font-weight:700}
#buildingPopover {z-index:3;position:fixed;width:min(290px,80vw);max-height:80dvh;overflow:auto;padding:10px 12px;color:#26392f;background:#fff1ce;border:2px solid #998054;border-radius:12px;box-shadow:0 4px 14px #1b2e2460}
#buildingPopover h3 {font:700 17px Georgia,serif;margin:0 30px 3px 0}
#buildingPopover p {margin:0 20px 5px 0;font-size:12px;line-height:1.3}
#buildingPopover>small {font-size:11px;color:#51604c}
.close-inspect {position:absolute;right:3px;top:3px;width:31px;height:31px;border:0;background:transparent;font-size:20px}
.inspect-actions {display:flex;align-items:stretch;gap:5px;margin-top:6px}
.inspect-actions button {font-size:12px;padding:5px 7px}
.inspect-actions button+button {background:#f6e5be}
.inspect-actions button:disabled {opacity:.5}
.inspect-actions small {display:block;font-size:9px;font-weight:600}

#companionSkill {
  position:absolute; right:32px; bottom:65px; width:62px; height:62px; border-radius:50%;
  border:2px solid #efd19a; background:radial-gradient(at 35% 22%,#577b67,#213a32 85%);
  box-shadow:0 3px 0 #453b24,0 3px 10px #14271c90; padding:0; pointer-events:auto; touch-action:none; user-select:none;
}
#companionSkill[hidden]{display:none}
#companionSkill img {width:88%;height:88%;object-fit:contain;pointer-events:none}
#companionSkill b {position:absolute;bottom:-9px;left:50%;transform:translateX(-50%);white-space:nowrap;font:600 10px system-ui;color:#fff2d5;background:#293e31;border-radius:9px;padding:2px 6px;}
#companionSkill output{position:absolute;inset:0;display:grid;place-items:center;color:white;font:bold 22px system-ui;text-shadow:0 1px 3px black;border-radius:50%;background:conic-gradient(#141e23d9 var(--shade),transparent 0);}
#companionSkill:disabled{opacity:1}
#companionSkill.aiming:before{content:"";position:absolute;inset:-14px;border-radius:50%;border:2px solid #fae5a8;background:#1c403f99}
#companionSkill.aiming i{position:absolute;left:calc(50% - 14px);top:calc(50% - 14px);width:28px;height:28px;border-radius:50%;background:#f0d69a;border:2px solid #fff2bf;z-index:1}

#toolPicker {
  position:absolute;right:104px;bottom:71px;width:46px;height:46px;
  padding:3px;border:1px solid #e7ca91;border-radius:50%;background:#294537;
  box-shadow:0 2px 4px #192f24a0;pointer-events:auto;touch-action:manipulation;
}
#toolPicker img{width:100%;height:100%;object-fit:contain}
#toolPicker[hidden]{display:none}
#mentorHome #mentor {left:calc(max(12px,env(safe-area-inset-left)) + 143px);right:calc(max(12px,env(safe-area-inset-right)) + 178px);width:auto;max-width:600px;margin-inline:auto;transform:none}
#mentorHome #mentor>img,#content #mentor>img {width:clamp(85px,14vw,166px);height:auto;flex:none;align-self:flex-end;object-fit:contain}
#content #mentor>img {width:clamp(78px,11vw,125px)}
#mentorStatus {letter-spacing:normal}
#mentorReplay {margin-left:auto}
.mentor-actions button {pointer-events:auto}
#mentor.on-watch>img,#mentor.on-watch #mentorText {display:none}
body:has(#mentorHome #mentor:not([hidden])) #guide.ambient {visibility:hidden}
@media(max-width:700px){#mentorHome #mentor{left:132px;right:136px}#mentorHome #mentor>img{width:82px}.mentor-card{padding:6px 8px}}
@media(max-width:560px){#mentorHome #mentor{left:5vw;right:5vw;bottom:calc(clamp(108px,31vmin,138px) + 24px)}}
#wallTools:not([hidden]),#gateTurn:not([hidden]) {position:fixed;z-index:4;left:50%;transform:translateX(-50%);bottom:max(16px,env(safe-area-inset-bottom));padding:6px;border-radius:12px;background:#fff2d4;color:#413420;box-shadow:0 3px 8px #16282055}
#wallTools:not([hidden]) {display:flex;align-items:center;gap:4px}
#wallTools button,#gateTurn {border:1px solid #ac915f;border-radius:7px;background:#f4e6c0;color:#392f1d;font-weight:700;min-height:36px}
#wallTools button[aria-pressed=true] {color:#fff;background:#456447}
#wallCount {white-space:nowrap;font-weight:700;padding:0 5px}

body:is([data-input=keyboard],[data-input=gamepad]) #stick {visibility:hidden;pointer-events:none}
body:is([data-input=keyboard],[data-input=gamepad]) button:focus-visible {outline:3px solid #ffd56d;outline-offset:2px}
body[data-input=keyboard] button[data-key]::after {content:attr(data-key)}
body[data-input=gamepad] button[data-pad]::after {content:attr(data-pad)}
body[data-input=keyboard] :is(#content,#buildingPopover) button:not([data-key])::after {content:"↵"}
body[data-input=gamepad] :is(#content,#buildingPopover) button:not([data-pad])::after {content:"A"}
body:is([data-input=keyboard],[data-input=gamepad]) :is(button[data-key],#content button,#buildingPopover button)::after {
  display:inline-block;align-self:center;flex:0 0 auto;min-width:1.25em;margin-inline:3px;padding:1px 3px;
  border:1px solid #ac956a;border-radius:4px;background:#343c30;color:#ffeec6;
  font:700 10px/1.15 system-ui;text-align:center;vertical-align:middle;pointer-events:none;
}
body:is([data-input=keyboard],[data-input=gamepad]) :is(#mapBtn,#companionSkill,#toolPicker,#profile,#action)::after {position:absolute;right:4px;bottom:3px}
body:is([data-input=keyboard],[data-input=gamepad]) #mapBtn {position:relative}
