/* ===== TAIMOVER v1 - CSS OTTIMIZZATO ===== */

/* === FONT LOADING === */
@font-face {
  font-family: 'Scratches3';
  src: local('Scratches'), url('../fonts/Scratches.otf') format('opentype');
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

/* === CSS VARIABLES === */
:root {
  --paper: #fdf8ee;
  --ink: #1f1a16;
  --plan: #ff6b6b;
  --focus: #ffd166;
  --review: #7860ff;
  --fun: #5ecf8e;
  --card-w: min(94vw, 560px);
  --vh: 1vh; /* mobile viewport fix */
}

/* === RESET & BASE === */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  background: #f3efe7;
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* === LAYOUT === */
.app {
  width: var(--card-w);
  max-width: 100%;
  user-select: none;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 2px;
  height: calc(var(--vh, 1vh) * 100);
  padding: 6px 8px;
  margin: 0 auto;
}

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

.title-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-canvas {
  display: block;
  height: clamp(60px, 12vw, 90px);
}

/* Mobile: titolo più grande */
@media (max-width: 767px) {
  .title-canvas {
    height: clamp(65px, 13vw, 95px);
  }
}

/* Desktop: come v1.0 */
@media (min-width: 768px) {
  .title-canvas {
    height: clamp(42px, 10vw, 88px); /* come v1.0 */
  }
  .app {
    gap: 8px; /* come v1.0 */
  }
}

.version-canvas {
  width: 50px;
  height: 24px;
  flex-shrink: 0;
  transform: rotate(12deg);
}

/* Desktop/Tablet: badge sovrapposto */
@media (min-width: 768px) {
  .title-wrap {
    display: block;
    gap: 0;
  }
  
  .title-canvas {
    width: 100%;
    flex: none;
  }
  
  .version-canvas {
    position: absolute;
    transform: rotate(12deg);
    z-index: 15;
  }
}

.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;
}

/* === MAIN CARD === */
.card {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--paper);
  box-shadow: 0 3px 0 #00000020, 0 20px 40px #00000018;
  padding: 12px;
  overflow: hidden;
}

.paper-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .55;
  mix-blend-mode: multiply;
  background: repeating-linear-gradient(to bottom, transparent 0 22px, #c8c1b385 22px 23px);
}

.frame-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

/* === SECTIONS LAYOUT === */
.stack {
  display: grid;
  grid-template-rows: 5fr 40fr 5fr 10fr;
  gap: 10px;
  height: 100%;
}

.section {
  position: relative;
  overflow: hidden;
  background: #fffaf2;
  min-height: 0;
}

.fill-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.scribble-canvas {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.flash-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: transparent;
  opacity: 0;
}

/* === ANIMATIONS === */
@keyframes vibe {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(0.4px, -0.5px) rotate(-0.02deg); }
  50% { transform: translate(-0.5px, 0.4px) rotate(0.02deg); }
  75% { transform: translate(0.3px, 0.5px) rotate(-0.015deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.section.vibe {
  animation: vibe 120ms linear infinite;
}

@keyframes sectionFlash {
  0%, 100% { opacity: .4; }
  50% { opacity: .8; }
}

.flash-layer.flash {
  animation: sectionFlash 300ms ease-in-out 3;
}

/* === CONTROLS === */
.controls {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
  z-index: 100;
}

.card:hover .controls {
  opacity: 1;
  pointer-events: auto;
}

.controls.show {
  opacity: 1;
  pointer-events: auto;
}

.circle-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2.5px solid #2a241d;
  background: #fffaf2;
  box-shadow: 0 2px 0 #00000025, 0 10px 16px #00000018;
  display: grid;
  place-items: center;
  cursor: pointer;
  line-height: 1;
  color: #1f1a16;
  -webkit-text-fill-color: #1f1a16;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  font-family: 'Scratches3', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-variant-emoji: text;
}

.circle-btn:active {
  transform: scale(.98);
}

.circle-btn.small {
  width: 58px;
  height: 58px;
}

.circle-btn.big {
  width: 86px;
  height: 86px;
}

.circle-btn canvas.btn-ic {
  width: 66%;
  height: 66%;
  display: block;
}

/* === OVERLAY === */
.overlay-finished {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #ffffffc0;
  backdrop-filter: saturate(120%) blur(1.5px);
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
  z-index: 110;
}

.overlay-finished.show {
  opacity: 1;
  pointer-events: auto;
}

/* === COUNTERS === */
.counters {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin: 4px auto 2px;
  gap: 10px;
}

.counter {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 78px;
  text-align: center;
  font-weight: 900;
  padding: 18px 16px;
  color: var(--ink);
  background: #fffaf2;
  box-shadow: 0 2px 0 #00000025, 0 10px 16px #00000018;
}

.counter-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.counter span {
  position: absolute;
  inset: 0;
  opacity: 0;
}

/* === HINTS === */
.hint {
  text-align: center;
  opacity: .6;
  font-size: 12px;
  margin: 2px 0 0;
}

/* === RESPONSIVE === */
@media (hover: none) {
  .card:hover .controls {
    opacity: 0;
    pointer-events: none;
  }
  .controls.show {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 480px), (max-height: 700px) {
  .card {
    padding: 10px;
  }
  .stack {
    gap: 8px;
  }
  .counter {
    min-height: 68px;
    padding: 14px;
  }
  .hint {
    display: none;
  }
}

/* Assicura che su mobile la classe .show prevalga SEMPRE sul selettore :hover */
.card .controls.show,
.card:hover .controls.show {
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* === SETTINGS GEAR === */
.settings-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
  z-index: 20;
}

.settings-btn:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.settings-canvas {
  width: 24px;
  height: 24px;
  display: block;
}

/* Mobile: ghiera più piccola e posizionata diversamente */
@media (max-width: 767px) {
  .settings-btn {
    right: 4px;
    top: 8px;
    transform: none;
    padding: 6px;
  }
  
  .settings-canvas {
    width: 20px;
    height: 20px;
  }
}

/* === SETTINGS MODAL === */
.settings-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.settings-modal[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}

.settings-content {
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.settings-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink);
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--ink);
  transition: background-color 0.2s ease;
}

.close-btn:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.settings-body {
  padding: 24px;
}

.time-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.time-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.time-control label {
  font-weight: 500;
  color: var(--ink);
  font-size: 0.9rem;
}

.time-control input {
  padding: 12px 16px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  font-size: 1rem;
  background: white;
  transition: border-color 0.2s ease;
}

.time-control input:focus {
  outline: none;
  border-color: var(--focus);
}

.error-message {
  color: #d32f2f;
  margin-top: 4px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.error-message small {
  color: inherit;
  font-weight: 500;
}

.settings-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

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

.btn-primary:hover {
  background: #e6b952;
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.1);
  color: var(--ink);
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .settings-content {
    width: 95%;
    margin: 20px;
  }
  
  .settings-header {
    padding: 16px 20px 12px;
  }
  
  .settings-body {
    padding: 20px;
  }
  
  .settings-actions {
    flex-direction: column;
  }
  
  .btn-primary, .btn-secondary {
    width: 100%;
  }
}
