*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: #142018;
  background: #edf1ea;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

#app {
  height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 18px;
  gap: 14px;
}

#header {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid #d7dfd3;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(17, 35, 25, 0.06);
  z-index: 10;
}

#brand-block {
  display: grid;
  gap: 3px;
}

#brand-block strong {
  font-size: 22px;
  letter-spacing: 0;
}

#connection-status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #657668;
  font-size: 14px;
  font-weight: 700;
}

.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
}

.dot.connected {
  background: #2d9f65;
  box-shadow: 0 0 8px rgba(45, 159, 101, 0.4);
}

.dot.disconnected {
  background: #d6462f;
}

#turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  justify-content: center;
}

.player-badge {
  min-width: 94px;
  min-height: 44px;
  display: grid;
  place-items: center;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid #d7dfd3;
  border-radius: 8px;
  background: #f5f8f3;
  transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}

.player-badge.active {
  border-color: #d6462f;
  background: #fff3e9;
}

.player-badge.inactive {
  opacity: 0.62;
}

.badge-name {
  font-weight: 900;
}

.badge-score {
  min-width: 26px;
  color: #d6462f;
  font-size: 22px;
  font-weight: 900;
  text-align: right;
}

#turn-arrow {
  color: #d6462f;
  font-size: 22px;
  font-weight: 900;
  transition: transform 0.2s;
}

#turn-arrow.flipped {
  transform: scaleX(-1);
}

#turn-arrow.pulse {
  animation: arrowPulse 0.9s ease-in-out infinite;
}

@keyframes arrowPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

#reset-btn,
#logout-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 7px;
  color: #1f382a;
  background: #e8eee7;
  font-weight: 800;
}

#reset-btn {
  display: none;
}

#reset-btn:hover,
#logout-btn:hover {
  background: #dce7dc;
}

#reset-btn.confirm-reset {
  color: #fff;
  background: #d6462f;
}

#main-content {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(430px, 0.88fr) minmax(520px, 1.12fr);
  gap: 18px;
}

#scene-section {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(320px, 1fr) auto;
  gap: 14px;
}

#canvas-container {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid #193024;
  background: #17251c;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#held-dice {
  position: absolute;
  top: 92px;
  left: 32px;
  z-index: 10;
  display: flex;
  flex-direction: row;
  gap: 8px;
  pointer-events: none;
}

.held-pip {
  width: 42px;
  height: 42px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 5px;
  border-radius: 8px;
  border: 2px solid #f0c84d;
  background: #fffdf5;
  box-shadow: 0 0 10px rgba(240, 200, 77, 0.55);
}

.held-pip span {
  width: 7px;
  height: 7px;
  place-self: center;
  border-radius: 50%;
  background: transparent;
}

.held-pip.p1 span:nth-child(5) { background: #151815; }
.held-pip.p2 span:nth-child(3),
.held-pip.p2 span:nth-child(7) { background: #151815; }
.held-pip.p3 span:nth-child(3),
.held-pip.p3 span:nth-child(5),
.held-pip.p3 span:nth-child(7) { background: #151815; }
.held-pip.p4 span:nth-child(1),
.held-pip.p4 span:nth-child(3),
.held-pip.p4 span:nth-child(7),
.held-pip.p4 span:nth-child(9) { background: #151815; }
.held-pip.p5 span:nth-child(1),
.held-pip.p5 span:nth-child(3),
.held-pip.p5 span:nth-child(5),
.held-pip.p5 span:nth-child(7),
.held-pip.p5 span:nth-child(9) { background: #151815; }
.held-pip.p6 span:nth-child(1),
.held-pip.p6 span:nth-child(3),
.held-pip.p6 span:nth-child(4),
.held-pip.p6 span:nth-child(6),
.held-pip.p6 span:nth-child(7),
.held-pip.p6 span:nth-child(9) { background: #151815; }

#dice-hud {
  min-height: 82px;
  display: grid;
  grid-template-columns: 1fr minmax(150px, 220px) 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: #ffffff;
  border: 1px solid #d7dfd3;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(17, 35, 25, 0.05);
}

#turn-hint {
  color: #1c2f23;
  font-size: 22px;
  font-weight: 900;
  white-space: nowrap;
}

#roll-count {
  justify-self: end;
  color: #13221a;
  font-size: 28px;
  font-weight: 900;
  white-space: nowrap;
}

.roll-button {
  min-height: 54px;
  border-radius: 8px;
  color: #fff;
  background: #d6462f;
  font-size: 26px;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(214, 70, 47, 0.25);
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}

.roll-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #e24e35;
}

.roll-button:disabled {
  color: #eef1ed;
  background: #9ca7a0;
  box-shadow: none;
}

#score-section {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto auto;
  background: #ffffff;
  border: 1px solid #d4ddd2;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(17, 35, 25, 0.06);
}

#score-scroll {
  min-height: 0;
  overflow-y: auto;
}

#score-table {
  width: 100%;
  border-collapse: collapse;
  color: #142018;
  font-size: 22px;
}

#score-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

#score-table th {
  min-height: 58px;
  padding: 14px 12px;
  color: #253c2f;
  background: #f1f5ef;
  border-bottom: 2px solid #cbd6ca;
  border-right: 1px solid #dde5da;
  font-size: 22px;
  font-weight: 900;
}

#score-table th:last-child {
  border-right: 0;
}

#score-body {
  display: table-row-group;
}

#score-table td {
  min-height: 54px;
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid #e4ebe2;
  border-right: 1px solid #dde5da;
  line-height: 1.35;
}

#score-table td:last-child {
  border-right: 0;
}

.col-label {
  width: 36%;
  color: #253c2f;
  font-weight: 900;
  text-align: left !important;
}

.col-admin,
.col-guest {
  width: 32%;
}

.col-mine {
  background: #eaf6ee;
}

.col-other {
  background: #fbfcfa;
}

.section-row td {
  padding: 9px 12px 5px;
  color: #78907f;
  background: #f6f8f5;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: left;
}

#score-admin-upper,
#score-guest-upper {
  color: #203526;
  background: #edf5ee;
  font-size: 22px;
  font-weight: 900;
}

#score-admin-grand,
#score-guest-grand {
  color: #fff;
  background: #253a2d;
  border-top: 3px solid #253a2d;
  font-size: 28px;
  font-weight: 900;
}

.preview {
  color: rgba(31, 112, 77, 0.55);
  cursor: pointer;
  font-size: 25px;
  font-weight: 900;
  animation: previewBlink 1s ease-in-out infinite;
}

.preview:hover {
  color: #d6462f;
}

@keyframes previewBlink {
  0%,
  100% { opacity: 0.48; }
  50% { opacity: 1; }
}

.filled {
  color: #c93624;
  font-size: 25px;
  font-weight: 900;
}

.empty {
  color: #dce3da;
}

#score-actions {
  padding: 12px;
  border-top: 1px solid #e4ebe2;
}

#start-btn {
  width: 100%;
  min-height: 48px;
  font-size: 18px;
}

.primary-btn {
  border-radius: 8px;
  color: #fff;
  background: #d6462f;
  font-weight: 900;
}

.primary-btn:hover:not(:disabled) {
  background: #e24e35;
}

.primary-btn:disabled {
  color: #f2f4f1;
  background: #aeb8b1;
}

#game-result {
  display: none;
  margin: 0 12px 12px;
  padding: 14px;
  color: #273827;
  background: #fff8df;
  border: 1px solid #ead68c;
  border-radius: 8px;
  text-align: center;
}

#game-result.visible {
  display: block;
}

#game-result h2 {
  margin: 0;
  color: #253a2d;
}

#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(145deg, #223528 0%, #496a52 52%, #dfe6d8 100%);
}

#login-overlay.hidden {
  display: none;
}

#login-box {
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 18px;
  padding: 28px;
  background: #ffffff;
  border: 1px solid #dbe1d7;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16, 28, 20, 0.22);
}

#login-box h1 {
  margin: 0;
  font-size: 42px;
  letter-spacing: 0;
}

#login-form {
  display: grid;
  gap: 12px;
}

#login-form select,
#login-form input {
  min-height: 46px;
  width: 100%;
  padding: 0 12px;
  color: #142018;
  background: #fbfcfa;
  border: 1px solid #ccd5ca;
  border-radius: 6px;
}

#login-form button,
.danger-btn {
  min-height: 44px;
}

#login-error {
  min-height: 20px;
  margin: 0;
  color: #b53324;
  font-weight: 800;
}

.danger-btn {
  border-radius: 8px;
  color: #294436;
  background: #e7eee6;
  font-weight: 800;
}

#toast {
  font-weight: 800;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  #app {
    min-height: 100vh;
  }

  #main-content {
    grid-template-columns: 1fr;
  }

  #score-section {
    overflow: visible;
  }

  #score-scroll {
    overflow: visible;
  }
}

@media (max-width: 680px) {
  #app {
    padding: 10px;
  }

  #header {
    grid-template-columns: 1fr auto;
  }

  #turn-indicator {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    justify-content: stretch;
  }

  .player-badge {
    min-width: 0;
    flex: 1;
  }

  #scene-section {
    grid-template-rows: minmax(280px, 42vh) auto;
  }

  #dice-hud {
    grid-template-columns: 1fr;
  }

  #roll-count {
    justify-self: start;
  }

  #score-table {
    font-size: 18px;
  }

  #score-table th,
  #score-table td {
    padding: 9px 8px;
  }
}
