:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #d7dee6;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --wood: #d8a85d;
  --wood-dark: #8a5a22;
  --black: #111827;
  --white: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.is-mobile body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 13px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary,
button[type="submit"],
#sendChallengeButton,
#confirmYes {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover,
button[type="submit"]:hover,
#sendChallengeButton:hover,
#confirmYes:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.topbar p,
.game-header p,
.empty-game p {
  color: var(--muted);
  margin-top: 5px;
}

.nickname-form {
  display: flex;
  gap: 8px;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  min-height: 40px;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lobby-panel {
  padding: 16px;
  min-height: 560px;
}

.game-panel {
  padding: 18px;
  min-height: 560px;
}

.panel-title,
.game-header,
.user-row,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title span {
  background: #e6f3f1;
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 4px 9px;
  font-weight: 700;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.user-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.user-main {
  min-width: 0;
}

.user-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 145px;
}

.user-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.notice {
  border: 1px solid #a7c7bf;
  background: #eaf7f4;
  color: #134e4a;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

.empty-game {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 510px;
  text-align: center;
  gap: 10px;
}

.game-view {
  display: grid;
  gap: 14px;
}

.turn-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  min-width: 145px;
  text-align: right;
}

.turn-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.board-wrap {
  display: grid;
  justify-content: center;
  padding: 10px 0;
}

.board {
  --cell: min(38px, calc((100vw - 390px) / 15));
  display: grid;
  grid-template-columns: repeat(15, var(--cell));
  grid-template-rows: repeat(15, var(--cell));
  width: calc(var(--cell) * 15);
  height: calc(var(--cell) * 15);
  background-color: var(--wood);
  background-image:
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--wood-dark) calc(50% - 0.5px), var(--wood-dark) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--wood-dark) calc(50% - 0.5px), var(--wood-dark) calc(50% + 0.5px), transparent calc(50% + 0.5px));
  background-size: var(--cell) var(--cell);
  border: 2px solid var(--wood-dark);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  touch-action: manipulation;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  min-width: 0;
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  line-height: 0;
}

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

.stone {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.35);
  pointer-events: none;
}

.stone.black {
  background: radial-gradient(circle at 34% 28%, #3d4654, var(--black) 68%);
}

.stone.white {
  background: radial-gradient(circle at 34% 28%, #fff, var(--white) 70%);
  border: 1px solid #cbd5e1;
}

.stone.preview {
  opacity: 0.45;
  filter: saturate(0.9);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.45), 0 2px 5px rgba(15, 23, 42, 0.2);
}

.cell.last::after {
  content: "";
  position: absolute;
  inset: 39%;
  border-radius: 50%;
  background: #dc2626;
}

.actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.game-message {
  min-height: 24px;
  color: var(--muted);
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

.dialog-content {
  padding: 18px;
  display: grid;
  gap: 13px;
}

.dialog-content label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

menu {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 820px) {
  #app {
    width: 100%;
    padding: 10px 10px 18px;
  }

  .topbar,
  .layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: 23px;
  }

  h2 {
    font-size: 18px;
  }

  .nickname-form {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  input,
  select,
  button:not(.cell) {
    min-height: 44px;
  }

  .lobby-panel,
  .game-panel {
    min-height: auto;
  }

  .lobby-panel,
  .game-panel {
    padding: 12px;
  }

  .has-active-game .game-panel {
    order: -1;
  }

  .has-active-game .lobby-panel {
    max-height: 172px;
    overflow: auto;
  }

  .has-active-game .user-list {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  }

  .empty-game {
    min-height: 210px;
    padding: 20px 8px;
  }

  .game-view {
    gap: 10px;
  }

  .board {
    --cell: min(calc((100vw - 28px) / 15), 36px);
    border-radius: 6px;
  }

  .game-header {
    align-items: flex-start;
    display: grid;
    grid-template-columns: 1fr;
  }

  .turn-card {
    min-width: 0;
    width: 100%;
    text-align: left;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .actions button {
    padding-inline: 8px;
  }

  .game-message {
    font-size: 14px;
  }

  .game-message button {
    width: 100%;
    margin-top: 8px;
  }

  dialog {
    width: min(100vw - 20px, 420px);
  }

  .dialog-content {
    padding: 16px;
  }

  menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 430px) {
  .nickname-form {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .user-row {
    align-items: stretch;
  }

  .user-row button {
    min-width: 86px;
  }

  .board-wrap {
    padding: 6px 0;
  }
}
