/* ===== Base ===== */
body {
  margin: 0;
  background-color: #c4a882;
  font-family: "Noto Sans JP", "Hiragino Sans", sans-serif;
  min-height: 100vh;
}

/* ===== Wrapper (max-width / white bands) ===== */
#wrapper {
  max-width: 960px;
  margin: 0 auto;
  background-color: #faf4ec;
  min-height: 100vh;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
}

/* ===== Header ===== */
#title {
  background-color: #5d4037;
  padding: 28px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#titleContent {
  margin: 0;
  color: #fff;
  font-family: "Cinzel", serif;
  font-size: 2.4rem;
  letter-spacing: 6px;
  text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.4);
}

.header-sub {
  margin: 0;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.9rem;
  letter-spacing: 3px;
}

/* ===== Main layout ===== */
main {
  padding: 0 40px;
}

#game {
  display: flex;
  align-items: flex-start;
}

/* ===== Board ===== */
#board {
  margin: 8vh 6vh 8vh 0;
  display: grid;
  grid-template-columns: repeat(var(--board-size), min(calc(64vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px));
  grid-template-rows: repeat(var(--board-size), min(calc(64vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px));
  gap: 2px;
  border: 3px solid #1b5e20;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.cell {
  width: min(calc(64vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px);
  height: min(calc(64vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px);
  background-color: #388e3c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(calc(48vh / var(--board-size)), calc(75vw / var(--board-size) - 30px), 60px);
  cursor: pointer;
  transition: background-color 0.15s;
}

.cell:hover {
  background-color: #43a047;
}

.black {
  color: #1a1a1a;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.white {
  color: #f5f5f5;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.highlight {
  background-color: #81c784;
}

/* ===== Side panel ===== */
#panel {
  margin: 8vh 0;
  padding: min(2.5vh, 16px) min(2vh, 14px);
  background-color: #f5ede0;
  border: 2px solid #d7bfa0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(3vh, 16px);
  min-width: 130px;
}

.score-area {
  display: flex;
  flex-direction: column;
  gap: min(1.5vh, 10px);
  width: 100%;
}

.score-box {
  display: flex;
  align-items: center;
  gap: min(0.8vh, 7px);
  font-size: min(2.2vh, 14px);
  background-color: #fdf8f2;
  border: 1px solid #d7bfa0;
  border-radius: 6px;
  padding: min(0.8vh, 7px) min(1.2vh, 9px);
  font-family: "Noto Sans JP", sans-serif;
}

.score-label {
  flex: 1;
  font-weight: 700;
}

.score-value {
  font-weight: 700;
  font-size: min(2.8vh, 18px);
  min-width: 2ch;
  text-align: right;
}

.turn-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(0.5vh, 5px);
}

.turn-label {
  margin: 0;
  font-size: min(1.8vh, 12px);
  font-weight: 700;
  color: #555;
  letter-spacing: 2px;
}

.stone-icon {
  font-size: min(4vh, 26px);
}

#reset-btn {
  width: 100%;
  padding: min(1.2vh, 9px);
  font-size: min(1.8vh, 12px);
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 700;
  letter-spacing: 2px;
  background-color: #e53935;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#reset-btn:hover {
  background-color: #b71c1c;
}

/* ===== Pass Toast ===== */
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
}

#pass-toast {
  display: none;
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #4e342e;
  color: #fff;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 12px 28px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  z-index: 200;
}

#pass-toast.show {
  display: block;
  animation: toast-in 0.25s ease forwards;
}

#pass-toast.hide {
  display: block;
  animation: toast-out 0.25s ease forwards;
  pointer-events: none;
}

/* ===== Result Modal ===== */
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

#result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#result-overlay.open {
  display: flex;
  animation: overlay-in 0.25s ease forwards;
}

#result-overlay.open #result-modal {
  animation: modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#result-modal {
  background-color: #faf4ec;
  border: 3px solid #5d4037;
  border-radius: 16px;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  min-width: 260px;
}

#result-title {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 1.6rem;
  color: #5d4037;
  letter-spacing: 4px;
}

#result-message {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1b5e20;
  letter-spacing: 2px;
}

.result-score {
  display: flex;
  gap: 16px;
}

.result-score-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  background-color: #f5ede0;
  border: 1px solid #d7bfa0;
  border-radius: 6px;
  padding: 8px 14px;
  font-family: "Noto Sans JP", sans-serif;
}

#rematch-btn {
  padding: 12px 32px;
  font-size: 1rem;
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 700;
  letter-spacing: 2px;
  background-color: #5d4037;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#rematch-btn:hover {
  background-color: #3e2723;
}

@media (max-width: 600px) {
  #result-modal {
    padding: 28px 24px;
    margin: 0 16px;
    gap: 16px;
  }

  #result-title {
    font-size: 1.2rem;
  }

  #result-message {
    font-size: 1.2rem;
  }
}

/* ===== Landscape phone (short screens) ===== */
@media (max-height: 500px) and (min-width: 601px) {
  #result-modal {
    padding: 16px 28px;
    gap: 10px;
  }

  #result-title {
    font-size: 1.1rem;
  }

  #result-message {
    font-size: 1.1rem;
  }

  #rematch-btn {
    padding: 8px 24px;
    font-size: 0.9rem;
  }
}

@media (max-height: 500px) and (min-width: 601px) {
  #title {
    padding: 8px 20px;
  }

  #titleContent {
    font-size: 1.4rem;
    letter-spacing: 3px;
  }

  .header-sub {
    display: none;
  }

  #board {
    margin: 2vh 2vw 2vh 0;
    grid-template-columns: repeat(var(--board-size), min(calc(76vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px));
    grid-template-rows: repeat(var(--board-size), min(calc(76vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px));
  }

  .cell {
    width: min(calc(76vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px);
    height: min(calc(76vh / var(--board-size)), calc(100vw / var(--board-size) - 40px), 80px);
    font-size: min(calc(57vh / var(--board-size)), calc(75vw / var(--board-size) - 30px), 60px);
  }

  #panel {
    margin: 2vh 0;
  }
}

/* ===== Mobile ===== */
@media (max-width: 600px) {
  #title {
    padding: 14px 20px;
  }

  #titleContent {
    font-size: 1.6rem;
    letter-spacing: 3px;
  }

  main {
    padding: 0 10px;
  }

  #game {
    flex-direction: column;
    align-items: center;
  }

  #board {
    margin: 4vw auto 3vw;
    grid-template-columns: repeat(var(--board-size), calc((100vw - 40px) / var(--board-size)));
    grid-template-rows: repeat(var(--board-size), calc((100vw - 40px) / var(--board-size)));
  }

  .cell {
    width: calc((100vw - 40px) / var(--board-size));
    height: calc((100vw - 40px) / var(--board-size));
    font-size: calc(68vw / var(--board-size));
    touch-action: manipulation;
  }

  #panel {
    margin: 0 0 4vw;
    padding: 12px 16px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    min-width: unset;
  }

  .score-area {
    flex-direction: row;
    gap: 8px;
  }

  .score-box {
    font-size: 1rem;
    padding: 6px 10px;
  }

  .score-value {
    font-size: 1.2rem;
  }

  .turn-area {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .turn-label {
    font-size: 1rem;
  }

  .stone-icon {
    font-size: 1.8rem;
  }

  #reset-btn {
    padding: 10px 24px;
    font-size: 0.95rem;
    width: auto;
  }
}
