@font-face {
  font-family: 'SuperBoys';
  src: url('./Text/SuperBoys-vmW67.woff2') format('woff2'),
       url('./Text/SuperBoys-vmW67.ttf') format('truetype');
  font-display: swap;
}

:root {
  --color-ink: #17210f;
  --color-ink-muted: #4a5542;
  --color-surface: #fff8dc;
  --color-surface-card: #f5eed4;
  --color-surface-strong: #ffffff;
  --color-primary: #285b24;
  --color-primary-hover: #1c4219;
  --color-secondary: #7c4c22;
  --color-secondary-hover: #5e3716;
  --color-danger: #9e251b;
  --color-danger-hover: #7b1a13;
  --color-warning: #9e5b00;
  --color-focus: #0c3d94;
  --color-border: #d4c5a0;
  
  --shadow-dialog: 0 1rem 3rem rgb(0 0 0 / 55%);
  --shadow-card: 0 0.5rem 1.5rem rgb(0 0 0 / 15%);
  --shadow-btn: 0 4px 0 #122810;
  
  --radius-sm: 0.375rem;
  --radius: 0.75rem;
  --radius-lg: 1.25rem;
  
  --font-family-game: 'SuperBoys', system-ui, -apple-system, sans-serif;
  --font-family-base: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  
  --board-size: min(78vmin, 32rem);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  font-family: var(--font-family-base);
  color: var(--color-ink);
  background-color: #2b1f14;
}

body {
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background-color: #2b1f14;
  background-image: url('./Assets/Background_Calakus.png');
  background-image: image-set(
    url('./Assets/Background_Calakus.webp') type('image/webp'),
    url('./Assets/Background_Calakus.png') type('image/png')
  );
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

:focus-visible {
  outline: 0.22rem solid var(--color-focus);
  outline-offset: 0.22rem;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App Main Container */
#appRoot {
  width: 100%;
  max-width: 64rem;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* Main Menu */
#mainMenu {
  background: rgba(255, 248, 220, 0.92);
  backdrop-filter: blur(8px);
  padding: 2.5rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dialog);
  text-align: center;
  width: min(100%, 28rem);
  border: 3px solid #8b5a2b;
}

#gameTitle {
  font-family: var(--font-family-game);
  font-size: clamp(2.5rem, 8vw, 4rem);
  margin: 0 0 1.5rem 0;
  color: #8b3a1a;
  text-shadow: 2px 2px 0px #ffdf9e, 4px 4px 0px #3d1709;
  letter-spacing: 2px;
}

.menu-button-group {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-base);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.8rem 1.5rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  min-height: 48px;
  touch-action: manipulation;
  transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: translateY(2px);
}

.btn-primary {
  background-color: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 4px 0 #153312;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
}

.btn-secondary {
  background-color: var(--color-secondary);
  color: #ffffff;
  box-shadow: 0 4px 0 #412610;
}

.btn-secondary:hover {
  background-color: var(--color-secondary-hover);
}

.btn-danger {
  background-color: var(--color-danger);
  color: #ffffff;
  box-shadow: 0 4px 0 #57120c;
}

.btn-danger:hover {
  background-color: var(--color-danger-hover);
}

.btn-warning {
  background-color: var(--color-warning);
  color: #ffffff;
  box-shadow: 0 4px 0 #5e3600;
}

.btn-warning:hover {
  background-color: #804800;
}

.btn-sm {
  font-size: 0.95rem;
  padding: 0.4rem 0.8rem;
  min-height: 40px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.25rem;
}

.btn-block {
  width: 100%;
}

/* In-Game Top 3 Leaderboard (Top-Left) */
.in-game-leaderboard {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  width: 13.5rem;
  background: rgba(255, 248, 220, 0.94);
  backdrop-filter: blur(8px);
  border: 2px solid #8b5a2b;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 0.6rem 0.75rem;
  z-index: 10;
}

.in-game-leaderboard-title {
  margin: 0 0 0.4rem 0;
  font-family: var(--font-family-game);
  font-size: 0.95rem;
  color: #8b3a1a;
  text-align: center;
  border-bottom: 1px dashed #8b5a2b;
  padding-bottom: 0.3rem;
  letter-spacing: 0.5px;
}

.in-game-leaderboard-ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.in-game-leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0.15rem 0.25rem;
  border-radius: 4px;
}

.in-game-rank {
  font-weight: 800;
  width: 1.5rem;
  color: #8b3a1a;
}

.in-game-leaderboard-item.rank-1 .in-game-rank {
  color: #b78103;
}

.in-game-leaderboard-item.rank-2 .in-game-rank {
  color: #5c6bc0;
}

.in-game-leaderboard-item.rank-3 .in-game-rank {
  color: #a0522d;
}

.in-game-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 0.5rem;
}

.in-game-score {
  font-weight: 700;
  color: var(--color-primary);
}

.in-game-empty {
  margin: 0.3rem 0;
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  font-style: italic;
  text-align: center;
}

@media (max-width: 860px) {
  .in-game-leaderboard {
    position: static;
    width: var(--board-size);
    margin-bottom: 0.5rem;
  }
}

/* Game HUD & Area */
#gameContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 40rem;
}

.game-hud {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 248, 220, 0.92);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  border: 2px solid #8b5a2b;
  box-shadow: var(--shadow-card);
}

.hud-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.turn-indicator {
  margin: 0;
  font-weight: 700;
  color: #8b3a1a;
  font-size: 1rem;
}

.hud-stats {
  display: flex;
  gap: 1rem;
}

.stat-box {
  margin: 0;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--color-ink);
}

.stat-box output {
  color: #8b3a1a;
  font-size: 1.2rem;
}

/* Game Board */
#board {
  width: var(--board-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  padding: 0.6rem;
  background: rgba(139, 90, 43, 0.85);
  border: 4px solid #5a3816;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dialog);
}

.hole {
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  min-width: 44px;
  min-height: 44px;
  border: 3px solid #3d230d;
  border-radius: var(--radius);
  background: url('./Assets/tanah.png') center center no-repeat;
  background-size: cover;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hole:focus-visible {
  outline: 0.25rem solid #ffeb3b;
  outline-offset: -0.25rem;
}

.mole {
  display: block;
  width: min(85%, 8rem);
  height: auto;
  max-height: 90%;
  object-fit: contain;
  margin-inline: auto;
  pointer-events: none;
  animation: molePop 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes molePop {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Dialogs */
.dialog {
  position: fixed;
  inset: 0;
  padding: 1rem;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.dialog[hidden] {
  display: none !important;
}

.dialog-content {
  background: var(--color-surface);
  color: var(--color-ink);
  padding: 1.75rem;
  border-radius: var(--radius-lg);
  border: 3px solid #8b5a2b;
  box-shadow: var(--shadow-dialog);
  width: min(100%, 30rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.dialog-content.wide {
  width: min(100%, 56rem);
}

.dialog-content h2 {
  font-family: var(--font-family-game);
  font-size: 2rem;
  margin: 0 0 1rem 0;
  color: #8b3a1a;
  text-align: center;
}

.dialog-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.dialog-actions.vertical {
  flex-direction: column;
}

.dialog-actions .btn {
  flex: 1;
}

.selection-section {
  margin-bottom: 1.25rem;
  text-align: left;
}

.section-label {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  color: #8b3a1a;
  margin-bottom: 0.5rem;
}

.difficulty-button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.btn-diff-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.5rem;
  background: var(--color-surface-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  color: var(--color-ink);
}

.btn-diff-option strong {
  font-size: 1rem;
  color: #8b3a1a;
}

.btn-diff-option span {
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  font-weight: 500;
}

.btn-diff-option:hover {
  border-color: #8b5a2b;
  background: #fff8eb;
}

.btn-diff-option.active {
  background: #8b3a1a;
  border-color: #5c1e05;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(139, 58, 26, 0.35);
}

.btn-diff-option.active strong {
  color: #ffffff;
}

.btn-diff-option.active span {
  color: #ffe0b2;
}

.mode-select-group {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin: 0.5rem 0;
}

.btn-block {
  width: 100%;
}

/* Guide Dialog */
.guide-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin: 1.25rem 0;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--color-surface-card);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  text-align: left;
}

.guide-mole-thumb {
  width: 54px;
  height: 54px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: rgba(139, 90, 43, 0.12);
  border: 1px solid rgba(139, 90, 43, 0.25);
  padding: 3px;
}

.guide-item p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--color-ink);
}

/* Countdown Dialog */
.dialog-countdown .dialog-content {
  background: transparent;
  border: none;
  box-shadow: none;
  text-align: center;
}

.countdown-number {
  font-family: var(--font-family-game);
  font-size: clamp(6rem, 20vw, 10rem);
  color: #ffeb3b;
  text-shadow: 4px 4px 0 #8b3a1a, 8px 8px 0 #000000;
  margin: 0;
  animation: countdownPulse 0.95s ease-out infinite;
}

@keyframes countdownPulse {
  0% { transform: scale(0.6); opacity: 0; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--color-ink);
}

.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background-color: var(--color-surface-strong);
  color: var(--color-ink);
}

.form-group input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
  height: 1.5rem;
}

.form-group.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.form-group input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--color-primary);
}

.error-message {
  color: var(--color-danger);
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0.35rem 0 0 0;
  min-height: 1.2rem;
}

/* Leaderboards */
.leaderboard-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
}

.leaderboard-column {
  background: var(--color-surface-card);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.leaderboard-column h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1.15rem;
  color: #8b3a1a;
  text-align: center;
}

.leaderboard-list-ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px dashed var(--color-border);
  font-size: 0.95rem;
}

.leaderboard-rank {
  font-weight: 800;
  color: #8b3a1a;
  width: 2.2rem;
}

.leaderboard-item.rank-1 .leaderboard-rank {
  color: #b78103;
}

.leaderboard-item.rank-2 .leaderboard-rank {
  color: #5c6bc0;
}

.leaderboard-item.rank-3 .leaderboard-rank {
  color: #a0522d;
}

.leaderboard-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  font-weight: 700;
  color: var(--color-primary);
}

.empty-notice {
  text-align: center;
  color: var(--color-ink-muted);
  font-style: italic;
  margin: 1rem 0;
}

/* Game Over Summary */
.game-over-summary {
  text-align: center;
  margin: 1.5rem 0;
}

.final-score-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: #8b3a1a;
  margin: 0.5rem 0;
}

.badge-notice {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 700;
  display: inline-block;
  margin: 0.5rem 0;
}

.multiplayer-result-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: #8b3a1a;
}

/* Custom Cursor (Hammer Smash) */
.cursor {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 4.5rem;
  height: 4.5rem;
  background: url('./Assets/palu.png') no-repeat center center;
  background-size: contain;
  pointer-events: none;
  z-index: 9999;
  transform-origin: 25% 75%;
  transform: translate(-20%, -65%) rotate(15deg);
  transition: transform 0.12s ease-out;
  will-change: transform, left, top;
}

@media (hover: hover) and (pointer: fine) {
  body {
    cursor: none;
  }
  button, input, select, a {
    cursor: none;
  }
  .cursor {
    display: block;
  }
  .cursor.active {
    transform: translate(-35%, -45%) rotate(-45deg) scale(1.15);
    transition: transform 0.04s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

html.reduced-motion *,
html.reduced-motion *::before,
html.reduced-motion *::after,
html[data-reduced-motion="true"] *,
html[data-reduced-motion="true"] *::before,
html[data-reduced-motion="true"] *::after {
  animation: none !important;
  transition: none !important;
}

/* Responsive Breakpoints */
@media (max-width: 30rem) {
  :root {
    --board-size: min(94vw, calc(100dvh - 12rem));
  }
  #mainMenu {
    padding: 1.75rem 1.25rem;
  }
  .dialog-content {
    padding: 1.25rem 1rem;
  }
  .dialog-actions {
    flex-direction: column;
  }
}

@media (max-height: 32rem) and (orientation: landscape) {
  :root {
    --board-size: min(75vh, 22rem);
  }
  #appRoot {
    padding: 0.5rem;
  }
  #gameContainer {
    flex-direction: row;
    gap: 1rem;
    align-items: center;
    justify-content: center;
  }
  .game-hud {
    width: auto;
    flex-direction: column;
    height: var(--board-size);
    justify-content: space-around;
    margin-bottom: 0;
  }
  .hud-stats {
    flex-direction: column;
    gap: 0.5rem;
  }
}
