* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { width: 100%; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f7;
  overflow: hidden;
}

.container {
  width: 100vw;
  height: 100dvh;
  height: 100svh;
  max-width: 100vw;
  max-height: 100dvh;
  background: #fff;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

@media (min-width: 900px) and (min-height: 600px) {
  .container {
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  }
}

h1 {
  text-align: center;
  color: #1d1d1f;
  font-size: 1.6em;
  font-weight: 600;
  margin-bottom: 4px;
}

.home-screen,
.game-screen {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.home-screen { display: flex; }
.game-screen.active { display: flex; }

.instruction {
  text-align: center;
  font-size: 1.3em;
  color: #1d1d1f;
  margin: 0;
  font-weight: 600;
  flex: 1;
}

.topbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 6px 0;
  flex-shrink: 0;
}

.categories {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  grid-auto-rows: minmax(110px, 1fr);
  grid-auto-flow: row dense;
  gap: 10px;
  overflow: hidden;
  align-content: start;
  justify-content: center;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.category-btn {
  background: var(--cat-color, #007aff);
  border: none;
  border-radius: 14px;
  padding: 10px;
  color: white;
  font-size: 0.95em;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(0,0,0,0.10);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  gap: 6px;
  text-align: center;
}
.category-btn:hover {
  transform: translateY(-2px);
  filter: brightness(0.95);
}
.category-btn:active {
  transform: translateY(0);
  filter: brightness(0.88);
}
.category-btn[disabled] {
  background: #c7c7cc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.cat-icon {
  font-size: 28px;
  line-height: 1;
}
.cat-label {
  font-size: 0.95em;
  line-height: 1.1;
}

.home-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  margin-top: 4px;
  flex-shrink: 0;
}
.home-footer .hint {
  font-size: 0.85em;
  color: #6b7280;
}

.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  flex-shrink: 0;
}
.btn-home-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  padding: 8px;
  display: grid;
  place-items: center;
  background: #f2f2f7;
  color: #1d1d1f;
  border: 2px solid #d1d1d6;
}
.btn-home-icon svg { width: 20px; height: 20px; }
.header-spacer { width: 40px; height: 40px; }

/* GAME */
.choices {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  padding: 8px;
  overflow: hidden;
}
@media (orientation: landscape) {
  .choices { flex-direction: row; }
  .choice  { max-width: 50%; }
}
@media (orientation: portrait) {
  .choices { flex-direction: column; }
  .choice  { max-height: 50%; }
}

.choice {
  background: white;
  border: 3px solid #3a3a3c;
  border-radius: 16px;
  padding: 10px;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, opacity .3s ease, filter .3s ease;
  box-shadow: 0 0 0 rgba(0,0,0,0);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 0;
}
.choice:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.10);
}

.choice-media {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #fafafa 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(45deg, transparent 75%, #fafafa 75%) 0 0/16px 16px,
    linear-gradient(45deg, transparent 25%, #fafafa 25%) 8px 8px/16px 16px,
    linear-gradient(45deg, #fafafa 75%, transparent 75%) 8px 8px/16px 16px;
  outline: 1px solid rgba(0,0,0,0.06);
  overflow: hidden;
}

.choice-media img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: none;
}

.choice-name {
  margin-top: 6px;
  font-size: 1em;
  font-weight: 500;
  color: #1d1d1f;
  text-align: center;
  flex-shrink: 0;
}

.choice.disabled { pointer-events: none; }
.choice.dimmed   { filter: grayscale(1) brightness(0.6); opacity: 0.4; }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.95em;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}
.btn-home { background: #8e8e93; color: white; }
.btn-home:hover { background: #636366; }
.btn-next { background: #34c759; color: white; }
.btn-next:hover { background: #248a3d; }
.next-fab {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 9000;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
  display: none;
}
.next-fab.visible { display: inline-flex; align-items: center; gap: 6px; }

.btn-settings {
  background: #0a84ff;
  color: white;
  border-radius: 12px;
  padding: 8px 12px;
}
.btn-settings:hover { background: #0066cc; }

.clapping-hands {
  position: fixed;
  font-size: 80px;
  z-index: 10000;
  pointer-events: none;
}
@keyframes clap {
  0%, 100% { transform: scale(1) rotate(-10deg); }
  50% { transform: scale(1.2) rotate(10deg); }
}
.clapping { animation: clap 0.3s ease-in-out; }

/* Pannello impostazioni */
#settingsPanel {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
#settingsPanel .card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  width: min(820px, 92vw);
  max-height: 90vh;
  overflow: hidden;
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  position: sticky;
  top: 0;
  padding-bottom: 6px;
  background: #fff;
  z-index: 5;
  border-bottom: 1px solid #e5e5ea;
}
.settings-header h2 { margin: 0; }
.settings-subtitle {
  margin-top: 4px;
  color: #6b7280;
  font-size: 0.95em;
}
.settings-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.settings-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}
.settings-actions {
  position: sticky;
  position: -webkit-sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.9) 24%, #fff 100%);
  z-index: 6;
}
.settings-actions-shadow {
  height: 12px;
  width: 100%;
  position: absolute;
  inset: -12px 0 auto 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.06), transparent);
  opacity: 0.35;
  pointer-events: none;
}
.settings-actions-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 14px;
}
.settings-actions-buttons {
  display: flex;
  gap: 8px;
}
.settings-actions-text {
  color: #6b7280;
  font-size: 0.9em;
}

.voice-block {
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f6f8fb;
  margin-bottom: 8px;
}
.voice-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.voice-title {
  font-weight: 700;
  color: #1d1d1f;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}
.row .label { color: #1d1d1f; font-size: 0.98em; }
.row.cat  .label { font-weight: 700; }
.row.group .label { font-weight: 600; }

.cat-card {
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,0.04);
}
.cat-header {
  padding: 4px 0 8px;
}
.groups-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.group-block {
  border: 1px solid #f0f0f5;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fafafa;
}
.group-header {
  padding: 4px 0 6px;
}
.items-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}
.item-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  min-width: 180px;
  flex: 1 1 160px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}
.item-name {
  font-size: 0.95em;
  color: #1d1d1f;
}
.chip-switch .toggle { transform: scale(0.92); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.switch {
  width: 48px;
  height: 28px;
  background: #d1d1d6;
  border-radius: 999px;
  position: relative;
  transition: background .2s ease, box-shadow .2s ease;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: left .2s ease, transform .2s ease;
}
.toggle input:checked + .switch { background: #34c759; }
.toggle input:checked + .switch::after { left: 23px; }
.btn-home.ghost {
  background: transparent;
  color: #1d1d1f;
  border: 1px solid #d1d1d6;
}
.btn-home.ghost:hover {
  background: #f2f2f7;
}

@media (max-height: 450px) {
  .instruction { font-size: 1.2em; }
  .btn { padding: 8px 12px; font-size: 0.85em; }
  .choice-name { font-size: 0.9em; }
  .choices { gap: 8px; padding: 6px; }
}
