/* ===== Base / Reset ===== */
* { box-sizing: border-box; }
html, body { height: 100%; width: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: #111;
  background: #fafafa;
  overflow: hidden; /* keep study view stable */
}

/* Respect iOS safe areas */
@supports (padding: max(0px)) {
  body {
    padding:
      max(env(safe-area-inset-top), 0)
      max(env(safe-area-inset-right), 0)
      max(env(safe-area-inset-bottom), 0)
      max(env(safe-area-inset-left), 0);
  }
}

/* ===== Layout ===== */
.wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: min(1100px, 100vw);
  margin: 0 auto;
  padding: 12px;
  gap: 8px;
}

h1 {
  margin: 6px 4px 0 4px;
  font-size: clamp(1rem, 2.2vw, 1.4rem);
  font-weight: 600;
  color: #111;
  text-align: center;
}

/* Desktop controls visible by default; mobile toolbar hidden by default */
.controls { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }
.mobile-toolbar { display: none; }

/* Buttons */
button {
  cursor: pointer;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  color: #111;
}
button:hover { background: #f3f3f3; }
button:active { transform: translateY(0.5px); }

/* Stage where the card sits (height is set dynamically by JS for perfect fit) */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
}

/* Card: fixed 16:9 aspect, scales to fit */
.card {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #ffffff;
  border: 1px solid #e6e6e6;
  border-radius: 14px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  display: grid;
  grid-template-rows: 1fr;
  overflow: hidden;
}

.frame {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: clamp(6px, 1.2vw, 12px);
}

img.cardface {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain; /* keep image fully visible */
  border-radius: 8px;
}

/* ===== Mobile toolbar ===== */
.mobile-toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-bottom)) 12px 12px 12px;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(6px);
  border-top: 1px solid #e6e6e6;
}

.mobile-toolbar button {
  font-size: 16px; line-height: 1;
  min-width: 44px; min-height: 44px;
  padding: 12px 14px; border-radius: 12px;
  border: 1px solid #ddd; background: #fff; color: #111;
}

.mobile-toolbar .grow {
  flex: 1 1 auto; display: flex; gap: 8px; justify-content: center;
}

/* ===== Responsive behavior: show only one toolbar ===== */
@media (max-width: 768px) {
  .controls { display: none; }      /* hide desktop controls on small screens */
  .mobile-toolbar { display: flex; }/* show mobile toolbar on small screens */
}

/* ===== Landscape refinements for short viewports ===== */
@media (orientation: landscape) and (max-height: 480px) {
  h1 { display: none; }
  .wrap { padding: 8px; }
  .stage { padding: 6px; }
  .mobile-toolbar button { padding: 10px 12px; min-height: 40px; }
}
