:root {
  color-scheme: light;
  --ink: #061d16;
  --muted: #60766d;
  --green: #1da85b;
  --green-deep: #0b6d43;
  --blue: #2f7cf6;
  --gold: #f3d16d;
  --cream: #fff7cf;
  --piece-ink: #17140c;
  --piece-red: #9f2d1c;
  --piece-wood: #e9bd63;
  --piece-wood-light: #fff2bd;
  --piece-silver: #bfc8c6;
  --piece-silver-light: #f6fbf8;
  --piece-silver-dark: #71817d;
  --line: rgba(7, 79, 48, 0.16);
  --panel: rgba(255, 255, 255, 0.68);
  --shadow: 0 22px 70px rgba(10, 67, 44, 0.2);
  --radius: 8px;
  font-family:
    Inter, "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", Meiryo,
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f8fff4;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.42) 0 13%, transparent 13% 22%, rgba(255, 255, 255, 0.18) 22% 34%, transparent 34%),
    radial-gradient(circle at 18% 8%, rgba(47, 124, 246, 0.14), transparent 20rem),
    radial-gradient(circle at 84% 14%, rgba(255, 218, 99, 0.24), transparent 20rem),
    linear-gradient(180deg, #fbfff5 0%, #ddf7b1 48%, #83d36d 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

.game-nav {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 10px max(16px, calc((100vw - 1180px) / 2));
  background: rgba(255, 255, 255, 0.74);
  border-bottom: 1px solid rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(18px) saturate(1.35);
}

.brand-link strong {
  font-size: 1.12rem;
  font-weight: 1000;
  letter-spacing: 0;
}

.brand-link span {
  color: var(--green);
}

.room-link {
  display: inline-grid;
  min-height: 36px;
  place-items: center;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--green-deep);
  font-size: 0.78rem;
  font-weight: 1000;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: inset 0 0 0 1px var(--line);
}

.shogi-shell {
  display: grid;
  min-height: calc(100vh - 62px);
  place-items: start center;
  padding: 24px 16px 54px;
}

.shogi-machine {
  width: min(100%, 1180px);
}

.title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.title-row p {
  margin: 0 0 5px;
  color: var(--green-deep);
  font-size: 0.85rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.title-row h1 {
  margin: 0;
  color: #08351f;
  font-size: clamp(2.35rem, 7vw, 5.3rem);
  font-weight: 1000;
  line-height: 0.9;
  letter-spacing: 0;
}

.best-card {
  min-width: 118px;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.66);
  box-shadow: 0 12px 28px rgba(10, 85, 50, 0.12);
  text-align: right;
}

.best-card span,
.hud-row span,
.hand-panel > span,
.ad-slot span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 1000;
  line-height: 1;
  text-transform: uppercase;
}

.best-card strong {
  display: block;
  margin-top: 5px;
  color: var(--blue);
  font-size: 1.32rem;
  font-weight: 1000;
  line-height: 1;
}

.level-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.level-button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  color: #0b6d43;
  font-weight: 1000;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.74);
  box-shadow:
    inset 0 0 0 1px var(--line),
    0 10px 24px rgba(10, 85, 50, 0.08);
}

.level-button.active {
  color: #fff;
  background: linear-gradient(135deg, #3ece6c, #087044);
}

.level-max.active {
  background: linear-gradient(135deg, #141d18, #0b6d43);
}

.hud-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.hud-row div {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 12px 30px rgba(10, 85, 50, 0.1);
}

.hud-row strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 1000;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-field {
  display: grid;
  grid-template-columns: minmax(112px, 0.38fr) minmax(360px, 640px) minmax(112px, 0.38fr);
  gap: 12px;
  align-items: stretch;
}

.board-wrap,
.hand-panel {
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.46)),
    rgba(255, 255, 255, 0.52);
  box-shadow:
    0 28px 82px rgba(10, 67, 44, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px) saturate(1.18);
}

.board-wrap {
  position: relative;
  padding: 14px;
}

.course-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 0 13px;
  border-radius: 999px;
  color: #0a6c43;
  background: rgba(255, 255, 255, 0.66);
  box-shadow: inset 0 0 0 1px var(--line);
}

.course-ribbon span,
.course-ribbon strong {
  font-size: 0.78rem;
  font-weight: 1000;
}

.shogi-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  align-items: stretch;
  justify-items: stretch;
  overflow: hidden;
  padding: 8px;
  border: 5px solid rgba(255, 255, 255, 0.84);
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.34), transparent 17rem),
    linear-gradient(90deg, rgba(13, 96, 54, 0.12), transparent 16%, rgba(255, 255, 255, 0.18) 50%, transparent 84%, rgba(7, 88, 51, 0.12)),
    repeating-linear-gradient(105deg, rgba(255, 255, 255, 0.16) 0 18px, rgba(20, 119, 64, 0.12) 18px 42px),
    linear-gradient(135deg, #aceb75, #3aae68);
  box-shadow:
    inset 0 0 0 1px rgba(5, 78, 45, 0.18),
    inset 0 16px 44px rgba(255, 255, 255, 0.14),
    inset 0 -28px 52px rgba(6, 91, 49, 0.2);
}

.shogi-board::before {
  position: absolute;
  inset: 8px;
  z-index: 0;
  content: "";
  border-radius: 7px;
  background:
    radial-gradient(ellipse at 84% 18%, rgba(248, 255, 214, 0.2) 0 5%, transparent 6%),
    radial-gradient(ellipse at 81% 18%, rgba(8, 78, 45, 0.14) 0 1.8%, transparent 2.3%),
    linear-gradient(105deg, transparent 0 78%, rgba(164, 41, 38, 0.16) 78% 79.6%, transparent 79.8%),
    linear-gradient(90deg, transparent 0 79.2%, rgba(255, 255, 255, 0.22) 79.2% 79.8%, transparent 80%),
    radial-gradient(ellipse at 36% 68%, rgba(255, 226, 107, 0.14) 0 12%, transparent 13%),
    radial-gradient(ellipse at 18% 27%, rgba(255, 255, 255, 0.14) 0 10%, transparent 11%),
    repeating-radial-gradient(ellipse at 45% 50%, transparent 0 54px, rgba(255, 255, 255, 0.13) 56px 58px, transparent 62px 116px);
  opacity: 0.58;
  pointer-events: none;
}

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.22);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.26),
    inset 0 -8px 10px rgba(11, 84, 48, 0.08);
  backdrop-filter: saturate(1.04);
}

.cell:hover {
  background: rgba(255, 255, 255, 0.34);
}

.cell.selected {
  background: rgba(47, 124, 246, 0.34);
  box-shadow:
    inset 0 0 0 3px rgba(47, 124, 246, 0.78),
    0 0 0 3px rgba(255, 255, 255, 0.62);
}

.cell.last-from {
  background: rgba(255, 255, 255, 0.3);
}

.cell.last-to::before {
  position: absolute;
  inset: 7%;
  z-index: 1;
  content: "";
  border: 1px solid rgba(255, 247, 199, 0.62);
  border-radius: 8px;
  box-shadow:
    0 0 18px rgba(255, 242, 142, 0.18),
    inset 0 0 16px rgba(47, 124, 246, 0.12);
  pointer-events: none;
  animation: lastMoveBreath 1.8s ease-out both;
}

.cell.legal::after {
  position: absolute;
  width: 18%;
  height: 18%;
  content: "";
  border-radius: 50%;
  background: rgba(5, 74, 43, 0.7);
}

.piece {
  position: relative;
  display: grid;
  isolation: isolate;
  z-index: 2;
  width: 81%;
  height: 89%;
  min-width: 0;
  min-height: 0;
  place-items: center;
  color: var(--piece-ink);
  font-family:
    "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Noto Serif JP",
    "Times New Roman", serif;
  font-weight: 1000;
  line-height: 1;
  text-align: center;
  background:
    radial-gradient(circle at 32% 20%, rgba(255, 255, 255, 0.72) 0 6%, transparent 7%),
    linear-gradient(108deg, rgba(255, 255, 255, 0.48), transparent 25%, rgba(116, 65, 19, 0.08) 72%, rgba(63, 31, 9, 0.22)),
    repeating-linear-gradient(96deg, rgba(115, 69, 24, 0.12) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--piece-wood-light), var(--piece-wood) 60%, #c78e3d);
  box-shadow:
    inset 0 3px 2px rgba(255, 255, 255, 0.58),
    inset 4px 0 7px rgba(255, 247, 198, 0.18),
    inset -4px 0 8px rgba(86, 42, 10, 0.18),
    inset 0 -7px 11px rgba(92, 49, 13, 0.28);
  clip-path: polygon(50% 0, 91% 18%, 83% 100%, 17% 100%, 9% 18%);
  filter:
    drop-shadow(0 9px 5px rgba(21, 55, 35, 0.24))
    drop-shadow(0 2px 0 rgba(97, 50, 15, 0.18))
    drop-shadow(0 1px 0 rgba(255, 255, 255, 0.28));
}

.piece::before {
  position: absolute;
  inset: 5% 8% 11%;
  z-index: -1;
  content: "";
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.32), transparent 35%, rgba(116, 65, 19, 0.1)),
    repeating-linear-gradient(83deg, transparent 0 6px, rgba(87, 45, 12, 0.08) 6px 8px);
  opacity: 0.72;
}

.piece::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  border-radius: 4px;
  background:
    linear-gradient(90deg, rgba(62, 32, 10, 0.16), transparent 13% 84%, rgba(255, 255, 255, 0.18)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 48%, rgba(62, 32, 10, 0.2));
}

.piece span {
  display: block;
  z-index: 2;
  font-size: clamp(1.05rem, 3.35vw, 1.92rem);
  letter-spacing: 0;
  pointer-events: none;
  text-shadow:
    0 1px 0 rgba(255, 247, 210, 0.42),
    0 2px 2px rgba(76, 44, 13, 0.18);
  transform: translateY(4%);
}

.piece.cpu {
  color: #17231f;
  background:
    radial-gradient(circle at 32% 20%, rgba(255, 255, 255, 0.84) 0 6%, transparent 7%),
    linear-gradient(108deg, rgba(255, 255, 255, 0.56), transparent 24%, rgba(60, 79, 75, 0.12) 70%, rgba(47, 63, 59, 0.28)),
    repeating-linear-gradient(96deg, rgba(69, 86, 82, 0.16) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--piece-silver-light), var(--piece-silver) 60%, var(--piece-silver-dark));
  box-shadow:
    inset 0 3px 2px rgba(255, 255, 255, 0.7),
    inset 4px 0 7px rgba(255, 255, 255, 0.18),
    inset -4px 0 8px rgba(31, 48, 44, 0.18),
    inset 0 -7px 11px rgba(35, 51, 47, 0.28);
  transform: rotate(180deg);
}

.piece.promoted {
  color: var(--piece-red);
  background:
    radial-gradient(circle at 32% 20%, rgba(255, 255, 255, 0.76) 0 6%, transparent 7%),
    linear-gradient(105deg, rgba(255, 255, 255, 0.34), transparent 28%),
    repeating-linear-gradient(96deg, rgba(115, 69, 24, 0.12) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #fff0aa, #e9b04e 58%, #c77735);
}

.piece.cpu.promoted {
  color: #8c2418;
  background:
    radial-gradient(circle at 32% 20%, rgba(255, 255, 255, 0.84) 0 6%, transparent 7%),
    linear-gradient(108deg, rgba(255, 255, 255, 0.56), transparent 24%, rgba(60, 79, 75, 0.12) 70%, rgba(47, 63, 59, 0.28)),
    repeating-linear-gradient(96deg, rgba(69, 86, 82, 0.16) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--piece-silver-light), var(--piece-silver) 60%, var(--piece-silver-dark));
  box-shadow:
    inset 0 3px 2px rgba(255, 255, 255, 0.7),
    inset 4px 0 7px rgba(255, 255, 255, 0.18),
    inset -4px 0 8px rgba(31, 48, 44, 0.18),
    inset 0 -7px 11px rgba(35, 51, 47, 0.28);
}

.cell.last-to .piece {
  filter:
    drop-shadow(0 9px 5px rgba(21, 55, 35, 0.24))
    drop-shadow(0 2px 0 rgba(97, 50, 15, 0.18))
    drop-shadow(0 0 9px rgba(255, 241, 137, 0.34));
}

.hand-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 100%;
  padding: 14px;
}

.hand-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hand-button {
  position: relative;
  display: grid;
  min-width: 52px;
  min-height: 48px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: #10251d;
  font-family:
    "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Noto Serif JP",
    serif;
  font-weight: 1000;
  cursor: pointer;
  background:
    repeating-linear-gradient(96deg, rgba(115, 69, 24, 0.1) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #fff2bd, #e5bd69);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    0 8px 14px rgba(21, 73, 45, 0.16);
}

.hand-button.cpu {
  color: #17231f;
  background:
    repeating-linear-gradient(96deg, rgba(69, 86, 82, 0.16) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--piece-silver-light), var(--piece-silver));
}

.hand-button.selected {
  outline: 3px solid var(--blue);
}

.hand-count {
  position: absolute;
  right: -5px;
  bottom: -5px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 0.72rem;
  background: var(--blue);
}

@keyframes lastMoveBreath {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }

  34% {
    opacity: 0.82;
    transform: scale(1);
  }

  100% {
    opacity: 0.5;
    transform: scale(1);
  }
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin: 16px 0 12px;
}

.control-row button,
.promotion-card button {
  display: inline-grid;
  min-width: 132px;
  min-height: 48px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-weight: 1000;
  cursor: pointer;
  background: var(--blue);
  box-shadow: 0 14px 32px rgba(21, 92, 213, 0.24);
}

#hint-button,
#sound-toggle,
#bgm-toggle,
#promote-no {
  color: #0a7445;
  background: rgba(255, 255, 255, 0.82);
  box-shadow:
    inset 0 0 0 1px var(--line),
    0 12px 28px rgba(11, 85, 50, 0.14);
}

.ad-slot {
  display: grid;
  min-height: 70px;
  place-items: center;
  border: 1px dashed rgba(16, 112, 67, 0.26);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
  text-align: center;
}

.ad-slot small {
  margin-top: 3px;
  color: #7c9087;
  font-weight: 800;
}

.promotion-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 26, 18, 0.48);
  backdrop-filter: blur(10px);
}

.promotion-modal[hidden] {
  display: none;
}

.promotion-card {
  display: grid;
  gap: 14px;
  width: min(340px, 100%);
  padding: 22px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
}

.promotion-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.promotion-card strong {
  font-size: 1.6rem;
  font-weight: 1000;
}

.promotion-card div {
  display: flex;
  gap: 10px;
  justify-content: center;
}

@media (max-width: 920px) {
  .play-field {
    grid-template-columns: 1fr;
  }

  .cpu-hand {
    order: 1;
  }

  .board-wrap {
    order: 2;
  }

  .player-hand {
    order: 3;
  }

  .hand-panel {
    min-height: 88px;
  }
}

@media (max-width: 640px) {
  .shogi-shell {
    padding: 16px 10px 42px;
  }

  .title-row {
    align-items: start;
  }

  .title-row h1 {
    font-size: clamp(2rem, 13vw, 3rem);
  }

  .best-card {
    min-width: 92px;
    padding: 9px 10px;
  }

  .level-row,
  .hud-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-wrap {
    padding: 10px;
    border-radius: 12px;
  }

  .shogi-board {
    padding: 5px;
    border-width: 4px;
    gap: 1px;
  }

  .cell {
    border-radius: 4px;
  }

  .piece {
    width: 92%;
    height: 92%;
  }

  .hand-list {
    gap: 6px;
  }

  .hand-button {
    min-width: 46px;
    min-height: 42px;
  }
}
