:root {
  color-scheme: light;
  --bg: #f2efe4;
  --panel: #fffaf0;
  --text: #2a2a2a;
  --muted: #5a5a5a;
  --accent: #106b4e;
  --accent-hover: #0b4e39;
  --border: #d4ccb8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #f8f4e8 0%, var(--bg) 65%);
}

body {
  overflow: hidden;
}

.app-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0.75rem;
  gap: 0.75rem;
}

.topbar,
.statusbar {
  background: color-mix(in srgb, var(--panel) 92%, white 8%);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.6rem 0.85rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  letter-spacing: 0.02em;
  font-weight: 700;
}

#reset-btn,
#scramble-btn {
  border: none;
  border-radius: 0.5rem;
  padding: 0.45rem 0.95rem;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
}

#reset-btn:hover,
#scramble-btn:hover {
  background: var(--accent-hover);
}

.stage-wrap {
  min-height: 0;
  border-radius: 0.8rem;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #ebe5d2;
  height: 100%;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.statusbar {
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .topbar,
  .statusbar {
    border-radius: 0.55rem;
    padding: 0.5rem 0.7rem;
  }

  #reset-btn,
  #scramble-btn {
    padding: 0.4rem 0.8rem;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .stage-wrap {
    min-height: 68vh;
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  .stage-wrap {
    min-height: 42vh;
  }
}

@media (orientation: landscape) and (hover: none) and (pointer: coarse),
  (orientation: landscape) and (any-hover: none) and (any-pointer: coarse),
  (orientation: landscape) and (max-height: 520px) and (max-width: 1024px) {
  .app-shell {
    grid-template-rows: 1fr;
    padding: 0;
    gap: 0;
    width: 100vw;
    height: 100svh;
  }

  .topbar {
    display: none;
  }

  .statusbar {
    display: none;
  }

  .stage-wrap {
    min-height: 100%;
    height: 100%;
    border: none;
    border-radius: 0;
  }
}
