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

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #e8e8e8;
  padding: 1rem;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
}

.page-header {
  text-align: center;
  padding-bottom: 0.25rem;
}

.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.page-header .subtitle {
  margin: 0;
  font-size: 0.95rem;
  opacity: 0.85;
}

.page-body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
  min-width: 0;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.left-column .card {
  margin-bottom: 0;
  min-width: 0;
  overflow-wrap: break-word;
}

.bank-block .balance-board,
.bank-block .bankruptcy-note,
.bank-block .loan-hint,
.bank-block .ability-index {
  overflow-wrap: break-word;
  word-break: break-word;
}

.bank-block .loan-hint {
  font-size: 0.78rem;
  line-height: 1.35;
}

.bank-block .bank-row {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.center-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-width: 0;
  text-align: center;
}

.center-column .card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.chart-panel {
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.chart-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.9;
}

.chart-wrap {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 8px;
  overflow: hidden;
}

#historyChart {
  display: block;
  width: 100%;
  height: auto;
  max-width: 340px;
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.history-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.history-list-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.9;
}

.download-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border: 2px solid #7ec87e;
  border-radius: 6px;
  background: rgba(126, 200, 126, 0.2);
  color: #7ec87e;
  cursor: pointer;
}

.download-btn:hover {
  background: rgba(126, 200, 126, 0.35);
}

.history-table-wrap {
  overflow: auto;
  max-height: 240px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.history-table th,
.history-table td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-table th {
  font-weight: 600;
  opacity: 0.9;
  white-space: nowrap;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table .cell-type {
  min-width: 7em;
  white-space: nowrap;
  word-break: normal;
}

.history-table .pl-win {
  color: #7ec87e;
}

.history-table .pl-lose {
  color: #e07c7c;
}

.help-panel {
  margin-top: 0;
}

.help-details {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.help-summary {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.help-summary::-webkit-details-marker {
  display: none;
}

.help-summary::before {
  content: "▶ ";
  font-size: 0.7em;
  opacity: 0.8;
}

.help-details[open] .help-summary::before {
  content: "▼ ";
}

.help-content {
  padding: 0.5rem 0.75rem 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
  opacity: 0.95;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.help-content p {
  margin: 0.35em 0;
}

.help-content p:first-child {
  margin-top: 0;
}

@media (max-width: 900px) {
  .page-body {
    grid-template-columns: 1fr;
  }

  .center-column .card {
    max-width: none;
  }
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.subtitle {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  opacity: 0.85;
}

.card {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.card-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.9;
}

.balance-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.balance-board strong {
  color: #f0c674;
}

.game-over-label {
  color: #e07c7c;
  font-weight: 600;
}

.bankruptcy-note {
  margin: -0.25rem 0 0.5rem;
  font-size: 0.75rem;
  opacity: 0.85;
  color: #b0b0b0;
}

.bank-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.bank-row .stake-input {
  width: 5.5rem;
}

.bank-row .repay-btn {
  border-color: #7ec87e;
  background: rgba(126, 200, 126, 0.2);
  color: #7ec87e;
}

.bank-row .repay-btn:hover:not(:disabled) {
  background: rgba(126, 200, 126, 0.35);
}

.loan-hint {
  margin: -0.5rem 0 0.5rem;
  font-size: 0.8rem;
  opacity: 0.9;
}

.ability-index {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #7eb8da;
}

.mode-section.card {
  margin-bottom: 1rem;
}

.mode-section {
  margin-bottom: 0;
}

.mode-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.9;
}

.mode-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.35rem;
}

.mode-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  border: 2px solid #3d5a80;
  border-radius: 8px;
  background: rgba(61, 90, 128, 0.3);
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.mode-btn:hover:not(:disabled) {
  background: rgba(61, 90, 128, 0.6);
  border-color: #5d7a9e;
}

.mode-btn[aria-pressed="true"] {
  background: #3d5a80;
  border-color: #7eb8da;
}

.mode-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.mode-desc {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.preset-row {
  margin-bottom: 0.35rem;
}

.preset-btn {
  flex: 1;
  max-width: 6rem;
}

.safe-panel {
  text-align: left;
}

.safe-panel.card {
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.safe-title {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.9;
}

.safe-note {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  opacity: 0.8;
}

.safe-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.safe-row .stake-input {
  flex: 1;
  min-width: 0;
}

.safe-status {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  opacity: 0.9;
}

.safe-actions {
  display: flex;
  gap: 0.5rem;
}

.stake-panel {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  text-align: left;
}

.stake-panel[hidden] {
  display: none;
}

.stake-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.stake-row label {
  min-width: 4.5em;
  font-size: 0.9rem;
}

.stake-input {
  width: 5rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.95rem;
  border: 2px solid #3d5a80;
  border-radius: 6px;
  background: rgba(61, 90, 128, 0.3);
  color: #e8e8e8;
}

.stake-input:focus {
  outline: none;
  border-color: #7eb8da;
}

.leverage-btns {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.leverage-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  border: 2px solid #3d5a80;
  border-radius: 6px;
  background: rgba(61, 90, 128, 0.3);
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.leverage-btn:hover {
  background: rgba(61, 90, 128, 0.6);
  border-color: #5d7a9e;
}

.stake-hint {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.75rem;
  opacity: 0.8;
}

.allin-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: 2px solid #c9a227;
  border-radius: 6px;
  background: rgba(201, 162, 39, 0.25);
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.2s;
}

.allin-btn:hover:not(:disabled) {
  background: rgba(201, 162, 39, 0.45);
}

.allin-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.export-row {
  margin-top: 1rem;
}

.export-row[hidden] {
  display: none;
}

.export-btn {
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  border: 2px solid #7ec87e;
  border-radius: 8px;
  background: rgba(126, 200, 126, 0.2);
  color: #7ec87e;
  cursor: pointer;
  transition: background 0.2s;
}

.export-btn:hover {
  background: rgba(126, 200, 126, 0.35);
}

.choice-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.choice-btn {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  border: 2px solid #3d5a80;
  border-radius: 8px;
  background: rgba(61, 90, 128, 0.3);
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.choice-btn:hover:not(:disabled) {
  background: rgba(61, 90, 128, 0.6);
  border-color: #5d7a9e;
}

.choice-btn[aria-pressed="true"] {
  background: #3d5a80;
  border-color: #7eb8da;
  box-shadow: 0 0 0 2px rgba(126, 184, 218, 0.4);
}

.choice-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.coin-wrap {
  perspective: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
  margin-bottom: 1.5rem;
}

.coin {
  position: relative;
  width: 80px;
  height: 80px;
  transform-style: preserve-3d;
}

.coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  backface-visibility: hidden;
  border: 3px solid #c9a227;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.3);
}

.coin-heads {
  background: linear-gradient(145deg, #e8d48b, #c9a227);
  color: #3d2a00;
}

.coin-tails {
  background: linear-gradient(145deg, #a89b6e, #8b7355);
  color: #2a1f0f;
  transform: rotateY(180deg);
}

.coin.flipping {
  animation: flip 0.6s ease-in-out forwards;
}

@keyframes flip {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(1800deg);
  }
}

.coin.result-heads {
  transform: rotateY(0deg);
}

.coin.result-heads .coin-heads {
  z-index: 1;
}

.coin.result-tails {
  transform: rotateY(180deg);
}

.coin.result-tails .coin-tails {
  z-index: 1;
}

.flip-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
}

.flip-disabled-reason {
  font-size: 0.9rem;
  color: #e07c7c;
  max-width: 280px;
}

.flip-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #e8b923, #c9a227);
  color: #1a1a2e;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.flip-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(201, 162, 39, 0.4);
}

.flip-btn:active:not(:disabled) {
  transform: translateY(0);
}

.flip-btn:disabled {
  background: #5a5a5a;
  color: #999;
  cursor: not-allowed;
}

.result {
  min-height: 1.5em;
  font-size: 1.1rem;
  font-weight: 500;
}

.result.win {
  color: #7ec87e;
}

.result.lose {
  color: #e07c7c;
}

@media (max-width: 380px) {
  .choice-row {
    flex-direction: column;
  }

  .choice-btn {
    width: 100%;
  }
}
