*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --sand: #f5e6c8;
  --sand-dark: #e8d4a8;
  --green: #5a9e4b;
  --green-light: #8bc34a;
  --water: #4fc3f7;
  --water-dark: #29b6f6;
  --wood: #8d6e63;
  --text: #4a3728;
  --text-light: #7d6b5d;
  --shadow: rgba(74, 55, 40, 0.15);
  --radius: 16px;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  background: linear-gradient(180deg, #87ceeb 0%, #f5e6c8 40%, #e8d4a8 100%);
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  margin: 0;
}

.app-wide {
  max-width: 560px;
}

.app {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 12px;
}

.screen.hidden {
  display: none;
}

.screen-password {
  align-items: center;
  background: linear-gradient(180deg, #87ceeb 0%, #f5e6c8 40%, #e8d4a8 100%);
}

.auth-card {
  background: white;
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px var(--shadow);
  text-align: center;
}

.auth-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--text);
}

.auth-lead {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

#password-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.25rem;
  text-align: center;
  letter-spacing: 0.3em;
  border: 2px solid #e0d4b8;
  border-radius: 12px;
  margin-bottom: 8px;
  font-family: inherit;
}

#password-input:focus {
  outline: none;
  border-color: var(--water-dark);
}

.auth-error {
  color: #d32f2f;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.auth-error.hidden {
  display: none;
}

.btn-block {
  width: 100%;
}

.menu-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: calc(100dvh - 200px);
  overflow-y: auto;
  padding: 4px 2px 12px;
  -webkit-overflow-scrolling: touch;
}

.level-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 6px 4px;
  border: none;
  border-radius: 10px;
  background: #f5ead0;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 1px 4px var(--shadow);
  touch-action: manipulation;
}

.level-cell:active {
  transform: scale(0.96);
}

.level-cell--cleared {
  background: linear-gradient(145deg, #b3e5fc, #81d4fa);
  color: #01579b;
  box-shadow: 0 2px 6px rgba(3, 169, 244, 0.25);
}

.level-cell-num {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.1;
}

.level-cell-size {
  font-size: 0.6rem;
  opacity: 0.75;
}

.btn-overlay-sub {
  margin-top: 10px;
  width: 100%;
}

@media (min-width: 400px) {
  .level-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (min-width: 520px) {
  .level-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}


.header {
  text-align: center;
  padding: 8px 4px 0;
}

.header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 4px;
  line-height: 1.5;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.level-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#level-label {
  font-weight: 700;
  font-size: 1rem;
}

.progress {
  font-size: 0.75rem;
  color: var(--text-light);
}

.buttons {
  display: flex;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 8px var(--shadow);
  touch-action: manipulation;
  min-height: 44px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--green-light), var(--green));
  color: white;
  padding: 14px 28px;
  font-size: 1rem;
}

.btn-secondary {
  background: white;
  color: var(--text);
}

#screen-game {
  width: 100%;
}

#screen-game .app {
  max-width: 100%;
  width: 100%;
  padding: 0 8px;
}

.board-wrap {
  position: relative;
  width: 100%;
  background: var(--sand-dark);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 4px 20px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(74, 55, 40, 0.45);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: white;
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90%;
}

.overlay-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.overlay-card h2 {
  font-size: 1.5rem;
  color: var(--green);
  margin-bottom: 8px;
}

.overlay-card p {
  color: var(--text-light);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.status-bar {
  text-align: center;
  padding: 4px 8px;
  min-height: 28px;
}

#status-text {
  font-size: 0.85rem;
  color: var(--text-light);
}

.footer {
  text-align: center;
  padding-bottom: 8px;
}

.footer p {
  font-size: 0.75rem;
  color: var(--text-light);
  opacity: 0.8;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (min-width: 400px) {
  .header h1 {
    font-size: 1.8rem;
  }
}
