:root {
  --ink: #34304a;
  --ink-soft: #6f6a86;
  --blue: #2a58c0;
  --panel: rgba(255, 251, 243, 0.9);
  --line: rgba(52, 48, 74, 0.08);
  --shadow: 0 8px 24px rgba(37, 40, 84, 0.16), 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  --font: "PingFang SC", "Hiragino Sans GB", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fcbea; }
body {
  font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; outline: none; }

#hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s; }
body.ready #hud { opacity: 1; }
#hud button, #hud .panel { pointer-events: auto; }
.panel { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* 左上：岛名与进度 */
#brand { position: absolute; left: 16px; top: 16px; display: flex; align-items: center; gap: 10px; padding: 9px 16px 9px 10px; min-width: 228px; }
#brand .logo { width: 44px; height: 40px; filter: drop-shadow(0 2px 2px rgba(42, 88, 192, .25)); animation: bob 1.1s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1.04, .94); } 45% { transform: translateY(-5px) scale(.97, 1.04); } }
.brand-text { flex: 1; }
.title { font-weight: 800; font-size: 17px; letter-spacing: .5px; display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
#rank { font-size: 12px; font-weight: 700; color: #fff; background: var(--blue); border-radius: 99px; padding: 1px 8px; }
.bar { margin-top: 6px; height: 7px; border-radius: 9px; background: rgba(42, 88, 192, .12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 9px; background: linear-gradient(90deg, #f6a8be, #f4c56b, #8fd07a); transition: width .5s; }
.next { margin-top: 4px; font-size: 11px; color: var(--ink-soft); white-space: nowrap; }

/* 上中：资源 */
#res { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); display: flex; gap: 4px; padding: 6px 8px; }
.chip { display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 8px; border-radius: 13px; min-width: 92px; }
.chip svg { width: 26px; height: 26px; flex: none; }
.chip b { font-size: 19px; font-variant-numeric: tabular-nums; min-width: 20px; }
.chip small { font-size: 11px; color: var(--ink-soft); }
.chip + .chip { border-left: 1px solid var(--line); border-radius: 0 13px 13px 0; }
.chip[data-k="dango"] b { color: var(--blue); }
.chip.bump svg { animation: bump .35s ease-out; }
.chip.bad { animation: shake .4s; }
.chip.bad b { color: #e0554f; }
@keyframes bump { 40% { transform: scale(1.3) translateY(-2px); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* 右上：时钟与按钮 */
#corner { position: absolute; right: 16px; top: 16px; display: flex; align-items: center; gap: 8px; }
#clock { display: flex; align-items: center; gap: 9px; padding: 7px 14px 7px 8px; }
.dial { position: relative; width: 36px; height: 36px; border-radius: 50%;
  background: conic-gradient(from 270deg, #ffe08a 0 25%, #ffc37a 25% 50%, #3b4b88 50% 75%, #253362 75% 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8); }
.dial i { position: absolute; left: 50%; top: 50%; width: 3px; height: 15px; margin-left: -1.5px; margin-top: -15px; border-radius: 3px; background: var(--ink); transform-origin: 50% 100%; }
.dial::after { content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; margin: -3.5px; border-radius: 50%; background: var(--ink); }
.clock-text { display: flex; flex-direction: column; line-height: 1.2; }
.clock-text b { font-size: 14px; }
.clock-text span { font-size: 12px; color: var(--ink-soft); }
.round-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--panel); box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center; font-size: 14px; font-weight: 800; transition: transform .15s; }
.round-btn:hover { transform: translateY(-2px); }
.round-btn:active { transform: scale(.94); }
.round-btn svg { width: 22px; height: 22px; }
.round-btn b { font-size: 19px; }
#soundBtn .mute { display: none; }
#soundBtn.off .mute { display: inline; }
#soundBtn.off .wave { display: none; }

/* 底部：手牌 */
#hand { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 12px; }
.card {
  position: relative; width: 112px; height: 156px; padding: 6px 6px 8px; border: 0; border-radius: 18px; cursor: pointer;
  background: #fffaf1; box-shadow: var(--shadow), 0 0 0 2px rgba(255, 255, 255, .9) inset;
  display: flex; flex-direction: column; align-items: center; transition: transform .18s cubic-bezier(.3, 1.6, .5, 1), box-shadow .18s;
}
.card:hover { transform: translateY(-6px); }
.card.selected { transform: translateY(-16px); box-shadow: 0 14px 30px rgba(42, 88, 192, .35), 0 0 0 3px var(--blue) inset; }
.card .art { width: 100%; height: 74px; border-radius: 13px; display: grid; place-items: center; overflow: hidden; }
.card[data-type="forest"] .art { background: linear-gradient(#dff3d2, #c5e6b0); }
.card[data-type="field"] .art { background: linear-gradient(#fff1c9, #f8dd99); }
.card[data-type="pond"] .art { background: linear-gradient(#d8f1fb, #b6e1f3); }
.card[data-type="mill"] .art { background: linear-gradient(#fde4dc, #f6c6b6); }
.card[data-type="house"] .art { background: linear-gradient(#ece5fb, #d7cbf3); }
.card .art img { width: 92px; height: 92px; margin-top: 4px; pointer-events: none; }
.card .name { margin-top: 6px; font-size: 16px; font-weight: 800; }
.card .cost { display: flex; align-items: center; gap: 2px; font-size: 13px; height: 20px; }
.card .cost svg { width: 18px; height: 18px; }
.card .cost b { font-variant-numeric: tabular-nums; }
.card .desc { font-size: 11px; color: var(--ink-soft); }
.card.poor .art { filter: grayscale(.65) opacity(.75); }
.card.poor .cost b { color: #e0554f; }
.card .kbd { position: absolute; top: 9px; left: 10px; z-index: 2; font-size: 10px; font-weight: 800; width: 17px; height: 17px; line-height: 17px; text-align: center; border-radius: 6px; background: rgba(255, 255, 255, .85); color: var(--ink-soft); }
.card.gift { background: linear-gradient(#fff7e0, #ffeec2); }
.card .ribbon { position: absolute; top: -9px; right: -6px; z-index: 2; font-size: 11px; font-weight: 800; color: #fff; background: #f08a4b; border-radius: 9px; padding: 2px 8px; box-shadow: 0 3px 8px rgba(240, 138, 75, .4); transform: rotate(6deg); }
.reroll { align-self: center; width: 76px; height: 92px; border: 0; border-radius: 16px; cursor: pointer; background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; transition: transform .15s; }
.reroll svg { width: 24px; height: 24px; color: var(--blue); }
.reroll b { font-size: 13px; }
.reroll small { font-size: 10px; color: var(--ink-soft); text-align: center; padding: 0 4px; line-height: 1.2; }
.reroll:hover:not(:disabled) { transform: translateY(-3px) rotate(-2deg); }
.reroll:disabled { opacity: .55; cursor: default; }
.reroll:disabled svg { color: var(--ink-soft); }

/* 提示 */
#hint { position: absolute; left: 50%; bottom: 196px; transform: translate(-50%, 8px); padding: 9px 18px; border-radius: 99px; background: rgba(52, 48, 74, .82); color: #fff; font-size: 14px; white-space: nowrap; opacity: 0; transition: opacity .35s, transform .35s; }
#hint.show { opacity: 1; transform: translate(-50%, 0); }
#hint b { color: #ffe08a; }
#toast { position: absolute; left: 50%; top: 84px; transform: translate(-50%, -10px); padding: 10px 20px; border-radius: 16px; background: #fffaf1; box-shadow: var(--shadow); font-size: 14px; opacity: 0; transition: opacity .3s, transform .3s; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast b { color: var(--blue); }
#tip { position: fixed; left: 0; top: 0; z-index: 20; max-width: 260px; padding: 9px 12px; border-radius: 12px; background: rgba(255, 251, 243, .96); box-shadow: var(--shadow); font-size: 12.5px; line-height: 1.55; pointer-events: none; opacity: 0; transition: opacity .15s; }
#tip.show { opacity: 1; }
#tip b { font-size: 14px; }
#tip small { margin-left: 8px; color: var(--ink-soft); }
#tip .bad { color: #e0554f; }

#pops { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 2px; padding: 2px 8px 2px 4px; border-radius: 99px; background: rgba(255, 251, 243, .92); box-shadow: 0 3px 10px rgba(37, 40, 84, .18); font-size: 13px; white-space: nowrap; will-change: transform; }
.pop svg { width: 18px; height: 18px; }
.pop.warn { background: rgba(255, 228, 220, .95); color: #b5473f; }

/* 帮助 */
#help { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(28, 30, 60, .35); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); transition: opacity .2s; }
#help.hidden { opacity: 0; pointer-events: none; }
.sheet { position: relative; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 26px; border-radius: 24px; background: #fffaf1; box-shadow: 0 20px 60px rgba(20, 20, 60, .3); -webkit-user-select: text; user-select: text; }
.sheet h2 { margin: 0 0 6px; font-size: 22px; display: flex; align-items: center; gap: 8px; }
.sheet h2 img { width: 32px; }
.sheet .lead { margin: 0 0 14px; font-size: 14px; line-height: 1.7; color: var(--ink-soft); }
.sheet .lead b { color: var(--ink); }
#helpClose { position: absolute; right: 14px; top: 14px; font-size: 22px; font-weight: 400; }
#helpTiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.help-row { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 14px; background: #fff; }
.help-row img { width: 64px; height: 64px; flex: none; }
.help-row b { font-size: 15px; }
.help-row p { margin: 2px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-soft); }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
.help-cols h3 { margin: 6px 0 4px; font-size: 15px; }
.help-cols ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.75; color: var(--ink-soft); }
.help-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 12px; color: var(--ink-soft); }
#resetBtn { border: 0; border-radius: 12px; padding: 8px 14px; background: #fde4dc; color: #b5473f; font-weight: 700; cursor: pointer; }

/* 拍照模式 */
#cover, #photoExit { display: none; }
body.photo #hud, body.photo #pops, body.photo #tip { display: none; }
body.photo #cover { display: flex; position: fixed; left: 4.2vw; bottom: 6.2vh; align-items: center; gap: 1.4vw; pointer-events: none; }
body.photo #photoExit { display: block; position: fixed; right: 16px; top: 16px; border: 0; border-radius: 99px; padding: 8px 16px; background: rgba(255, 251, 243, .85); box-shadow: var(--shadow); font-weight: 700; cursor: pointer; }
body.photo.shot #photoExit { display: none; }
#cover img { width: clamp(64px, 8.5vw, 140px); filter: drop-shadow(0 6px 10px rgba(10, 20, 60, .35)); }
.cover-title { font-size: clamp(42px, 6.2vw, 104px); font-weight: 900; letter-spacing: .06em; color: #fff; line-height: 1;
  text-shadow: 0 .05em 0 #1d3f94, 0 .1em .25em rgba(10, 20, 60, .45); -webkit-text-stroke: .02em #1d3f94; paint-order: stroke fill; }
.cover-sub { margin-top: .6vw; display: inline-block; font-size: clamp(14px, 1.65vw, 26px); font-weight: 700; color: #34304a; background: rgba(255, 251, 243, .9); border-radius: 99px; padding: .3em .9em; box-shadow: 0 4px 14px rgba(10, 20, 60, .2); }

/* 窄屏 */
@media (max-width: 1200px) {
  #res { top: 86px; }
  #toast { top: 146px; }
}
@media (max-width: 900px) {
  #brand { min-width: 0; }
  .next { display: none; }
  #clock .clock-text { display: none; }
  #clock { padding: 4px; }
}
@media (max-width: 640px) {
  #brand { left: 8px; top: 8px; padding: 6px 10px 6px 6px; }
  #brand .logo { width: 32px; height: 30px; }
  .title { font-size: 14px; }
  .brand-name { display: none; }
  #corner { right: 8px; top: 8px; gap: 5px; }
  .round-btn { width: 34px; height: 34px; }
  .round-btn svg { width: 18px; height: 18px; }
  #res { top: 60px; padding: 4px; }
  #toast { top: 110px; white-space: normal; width: max-content; max-width: 92vw; text-align: center; }
  .chip { min-width: 0; padding: 4px 6px; gap: 3px; }
  .chip small { display: none; }
  .chip b { font-size: 15px; }
  .chip svg { width: 20px; height: 20px; }
}
@media (max-width: 640px), (max-height: 500px) {
  #hand { bottom: 8px; gap: 6px; }
  .card { width: 76px; height: 118px; border-radius: 14px; padding: 4px 4px 6px; }
  .card .art { height: 52px; }
  .card .art img { width: 66px; height: 66px; }
  .card .name { font-size: 13px; margin-top: 3px; }
  .card .desc { display: none; }
  .card .kbd { display: none; }
  .reroll { width: 56px; height: 72px; }
  .reroll small { display: none; }
  #hint { bottom: 140px; font-size: 12px; white-space: normal; width: max-content; max-width: 92vw; text-align: center; }
  #helpTiles, .help-cols { grid-template-columns: 1fr; }
}
/* 横屏手机：资源条回到第一行，去掉文字标签 */
@media (max-height: 500px) and (min-width: 641px) {
  #res { top: 16px; padding: 4px 6px; }
  .chip { min-width: 0; padding: 4px 8px 4px 6px; }
  .chip small { display: none; }
  #toast { top: 76px; }
}
