:root {
  --card: rgba(255, 255, 255, .9);
  --card-solid: #ffffff;
  --field-bg: #f2faef;
  --line: rgba(46, 140, 70, .22);
  --text: #163a22;
  --muted: #5a7b62;
  --ok: #23a34a;
  --ok-2: #3cc567;
  --warn: #ff8a00;
  --op: #f0437a;
  --ready: #22c55e;
  --c0: #1f8bff;
  --c1: #f0437a;
  --c2: #ff9f1c;
  --c3: #22b35e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  overscroll-behavior: none;
}

/* 맑은 하늘 + 잔디 */
body {
  background:
    radial-gradient(ellipse 60% 40% at 20% 0%, rgba(255, 255, 255, .9), transparent 70%),
    linear-gradient(180deg, #eef9ff 0%, #d4efff 40%, #c9ecc0 72%, #9fd88f 100%);
  background-color: #d4efff;
  background-attachment: fixed;
}

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 18px 50px rgba(30, 110, 60, .18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  margin: auto;
}
.card.center { text-align: center; }

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { margin: 0 0 4px; font-size: 26px; }
.title-text {
  background: linear-gradient(90deg, #1f9d48, #2bb3a0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
h2 { margin: 0 0 8px; font-size: 28px; }
.logo { display: inline-block; animation: sway 2.4s ease-in-out infinite alternate; transform-origin: 30% 100%; }
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
.sub { color: var(--muted); margin: 6px 0 14px; font-size: 14px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--text);
  font-size: 16px; /* iOS 확대 방지 */
  outline: none;
}
.field input::placeholder { color: #9bb8a2; }
.field input:focus { border-color: var(--ok); box-shadow: 0 0 0 3px rgba(35, 163, 74, .18); background: #fff; }

.row { display: flex; gap: 8px; align-items: center; }
.row.gap { justify-content: center; margin-bottom: 8px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab { border: 0; background: transparent; padding: 10px; border-radius: 9px; color: var(--muted); font-weight: 700; }
.tab.active { background: #fff; color: var(--ok); box-shadow: 0 2px 8px rgba(30, 110, 60, .15); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  flex: 1 0 auto;
  min-width: 56px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  font-weight: 600;
}
.chips button.active { border-color: var(--ok); background: #fff; color: var(--ok); box-shadow: 0 0 0 2px rgba(35, 163, 74, .15); }

.primary {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--ok-2), var(--ok));
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  margin-top: 4px;
  box-shadow: 0 8px 22px rgba(35, 163, 74, .32);
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .5; }

.ghost {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ok);
  font-weight: 700;
  margin-top: 8px;
}
.ghost.wide { width: 100%; }

.icon-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 20px;
}
.icon-btn.small { width: 36px; height: 36px; font-size: 14px; }

.help-link {
  flex: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ok);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 800;
}

.rules { margin-top: 18px; font-size: 14px; color: var(--muted); }
.rules summary { cursor: pointer; color: var(--text); font-weight: 700; }
.rules ol { padding-left: 20px; line-height: 1.6; }
.rules b { color: var(--text); }

.conn { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; }
.conn.ok::before { content: "● "; color: var(--ready); }
.conn.bad::before { content: "● "; color: var(--op); }

.big-code { font-size: 44px; font-weight: 900; letter-spacing: 6px; margin: 4px 0 10px; word-break: break-all; color: var(--ok); }

.spinner {
  width: 40px;
  height: 40px;
  margin: 14px auto 8px;
  border: 4px solid rgba(35, 163, 74, .15);
  border-top-color: var(--ok);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .15); }
.dot.c0 { background: var(--c0); } .dot.c1 { background: var(--c1); } .dot.c2 { background: var(--c2); } .dot.c3 { background: var(--c3); }

.wait-list { list-style: none; margin: 6px auto 0; padding: 0; max-width: 260px; text-align: left; }
.wait-list li { padding: 8px 12px; margin: 6px 0; border-radius: 10px; background: var(--field-bg); border: 1px solid var(--line); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wait-list li.empty { color: #9fb9a6; font-weight: 500; border-style: dashed; }

/* ---- 조작법 ---- */
.help-card { max-width: 480px; max-height: calc(100dvh - 32px); overflow-y: auto; }
.help-card h2 { font-size: 24px; text-align: center; }
.help-figure {
  display: block;
  width: 100%;
  height: auto;
  margin: 4px 0 8px;
  border-radius: 14px;
  background: radial-gradient(ellipse 90% 120% at 30% -30%, rgba(255, 255, 255, .35), transparent 70%), linear-gradient(180deg, #5cb85a, #469b45);
}
.help-steps { list-style: none; padding: 0; margin: 0 0 12px; }
.help-steps li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  line-height: 1.5;
}
.help-steps li:last-child { border-bottom: 0; }
.help-steps .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(35, 163, 74, .1); font-size: 17px; }
.help-steps b { color: var(--text); }
.help-steps .op { color: var(--op); font-weight: 700; }
.help-steps .warn { color: var(--warn); font-weight: 700; }
.help-steps .grav { color: #2346c7; font-weight: 700; }
.sci-title { margin: 6px 0 2px; font-size: 16px; color: var(--ok); }
.sci-steps .ico { background: rgba(43, 179, 160, .14); }
.device { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 6px; background: rgba(35, 163, 74, .1); color: var(--ok); font-weight: 700; margin-right: 4px; }

/* ---- 게임 화면 ---- */
#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  background: #bfe3ff;
}

#hud {
  display: grid;
  grid-template-columns: 1fr minmax(0, 1.4fr) 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.hud-left, .hud-right { min-width: 0; }
.hud-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.hole-label { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.small-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.hud-mid { text-align: center; min-width: 0; }
.turn-label { font-weight: 900; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-bar { height: 6px; border-radius: 4px; background: #dcebdc; overflow: hidden; margin: 4px auto 3px; max-width: 220px; }
.turn-fill { height: 100%; width: 0; background: var(--ok); transition: background .2s; }
.turn-fill.urgent { background: var(--op); }
.stroke-label { font-weight: 900; font-size: 15px; white-space: nowrap; }
.board-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 800; color: var(--ok); white-space: nowrap; }

#stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: block;
}
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute;
  transform: translate(-50%, -100%);
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
.tag.c0 { background: var(--c0); } .tag.c1 { background: var(--c1); } .tag.c2 { background: var(--c2); } .tag.c3 { background: var(--c3); }
.tag.turn { outline: 2px solid #fff; font-size: 12px; }
.flabel {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.flabel.force { color: #c25e00; border: 2px solid var(--warn); }
.flabel.force.over { color: #d10000; border-color: #ff2020; }

.banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  animation: pop .35s ease-out;
  max-width: 92%;
}
.banner #bannerText { font-size: 40px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .18), 0 0 18px rgba(0, 0, 0, .25); white-space: nowrap; }
.banner #bannerSub { font-size: 15px; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, .45); margin-top: 2px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

.nogl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 700; padding: 20px; }

#footbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px;
  background: rgba(255, 255, 255, .92);
  border-top: 1px solid var(--line);
  z-index: 2;
}
.band-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.band-title { font-size: 12px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.band-chips { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 420px; }
.band-chips button {
  border: 1px solid var(--line);
  background: var(--field-bg);
  border-radius: 10px;
  padding: 5px 4px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.band-chips button.active { background: #fff; border-color: var(--ok); color: var(--ok); box-shadow: 0 0 0 2px rgba(35, 163, 74, .15); }
.band-swatch { display: block; width: 26px; border-radius: 3px; margin-bottom: 3px; }
.band-swatch.b0 { height: 3px; background: #8fd14f; }
.band-swatch.b1 { height: 5px; background: #f2b134; }
.band-swatch.b2 { height: 8px; background: #7a4bc2; }
.help-q { color: var(--ok); font-weight: 900; font-size: 17px; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(200, 235, 205, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
}
.overlay.soft { background: rgba(200, 235, 205, .3); backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; }
.overlay.fixed { position: fixed; }
.overlay .card { max-height: calc(100% - 8px); overflow-y: auto; }

.res-list { list-style: none; margin: 8px 0; padding: 0; text-align: left; }
.res-list li { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 700; }
.res-list li:last-child { border-bottom: 0; }
.res-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-list .sc { font-weight: 900; }
.res-list .lb { font-size: 12px; color: var(--muted); margin-left: 6px; min-width: 56px; text-align: right; }
.note { background: #eefaf6; border: 1px solid rgba(43, 179, 160, .35); border-radius: 12px; padding: 10px 12px; text-align: left; font-size: 14px; }
.note b { color: #1f7f86; }
.note p { margin: 4px 0 0; line-height: 1.5; }

.board-card { max-width: 560px; }
.table-wrap { overflow-x: auto; margin: 8px 0 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); }
td.nm { text-align: left; font-weight: 800; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
td.tot { font-weight: 900; }
tr.me td { background: rgba(35, 163, 74, .08); }
tr.win td.nm::after { content: " 👑"; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 74px));
  transform: translateX(-50%);
  background: var(--card-solid);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  z-index: 100;
  max-width: calc(100% - 32px);
  text-align: center;
  box-shadow: 0 10px 30px rgba(30, 110, 60, .2);
}
.toast.warn { background: #fff4e6; border-color: var(--warn); color: #8a4a00; }

/* 가로로 짧은 화면(가로 모드 휴대폰) */
@media (max-height: 480px) {
  #hud { padding: 3px 12px; }
  .turn-label { font-size: 15px; }
  #footbar { padding: 3px 12px 4px; }
  .band-chips button { padding: 2px 4px; flex-direction: row; gap: 4px; justify-content: center; }
  .band-swatch { display: none; }
  .banner #bannerText { font-size: 30px; }
}
@media (max-width: 480px) {
  #hud { grid-template-columns: 1fr 1.5fr 1fr; padding: 6px 8px; gap: 4px; }
  .hole-label { font-size: 14px; }
  .turn-label { font-size: 15px; }
  .stroke-label { font-size: 13px; }
  .band-title { display: none; }
  .banner #bannerText { font-size: 32px; }
}

/* 계정 칩 (아이디 · 골드 · 상점) */
.acct-slot { display: flex; justify-content: flex-end; margin: -6px -4px 10px; min-height: 40px; }
.acct-slot:empty { display: none; }
.kit-root h2 { font-size: 22px; }
.gold-line { margin: 4px 0 10px; font-weight: 800; color: #b87400; min-height: 1em; }
.gold-line:empty { display: none; }
