@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;600;700;800&display=swap');

/* ========================
   Base & Variables
   ======================== */
:root {
  --bg: #faf7f4;
  --card: #ffffff;
  --text: #2c2c2c;
  --text-soft: #888;
  --border: #e8e2dc;
  --accent: #333333;
  --accent-hover: #111111;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
}

body {
  font-family: 'Rubik', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  direction: rtl;
  overscroll-behavior-y: contain;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.hidden { display: none !important; }

/* ========================
   Accessibility (a11y)
   ======================== */
:focus-visible {
  outline: 3px solid #2d5a3d;
  outline-offset: 3px;
  border-radius: 4px;
}
button:focus-visible, 
input:focus-visible, 
a:focus-visible {
  outline: 3px solid #2d5a3d;
  outline-offset: 3px;
}

/* ========================
   Header
   ======================== */
.app-header {
  position: sticky;
  top: 0;
  height: 96px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-area > a + a {
  margin-right: 16px;
}

.shop-logo-link {
  flex-shrink: 0;
  text-decoration: none;
  line-height: 0;
}
.site-logo {
  height: 68px;
  width: auto;
  object-fit: contain;
}

.home-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: #2d5a3d;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.logo-text-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.logo-title {
  font-size: 1.3rem;
  font-weight: 900;
  color: #000;
  line-height: 1.1;
}
.logo-sub {
  font-size: 1.1rem;
  font-weight: 700;
  color: #000;
  line-height: 1.1;
  margin-top: -2px;
}

@media (max-width: 480px) {
  .app-header { height: 60px; }
  .header-inner { padding: 0 12px; }
  .site-logo { height: 44px; }
  .logo-area > a + a { margin-right: 10px; }
  .logo-icon { width: 34px; height: 34px; border-radius: 6px; }
  .logo-title { font-size: 1.1rem; }
  .logo-sub { font-size: 0.95rem; }
  .home-link { gap: 8px; }
}

/* ========================
   Hero
   ======================== */
.hero {
  text-align: center;
  padding: 50px 10px 28px; 
}
.hero h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.hero p {
  font-size: 1rem;
  color: var(--text-soft);
}

@media (max-width: 420px) {
  .hero { padding: 30px 4px 16px; } 
  .hero h1 { font-size: 1.5em; }
  .hero p { font-size: 0.9em; }
}

/* ========================
   Layout
   ======================== */
.app {
  flex: 1;
  max-width: 750px;
  margin: 0 auto;
  padding: 16px;
  width: 100%;
}

/* ========================
   Cards
   ======================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 14px;
}

.card-label {
  display: block;
  font-weight: 700;
  font-size: 1.05em;
  margin-bottom: 12px;
}

.card-hint {
  font-size: 0.9em;
  color: var(--text-soft);
  margin-bottom: 14px;
}

/* ========================
   Quantity Picker
   ======================== */
.qty-pick {
  display: flex;
  gap: 10px;
}

.qty-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.15s;
  min-height: 48px;
}
.qty-option:active { transform: scale(0.96); }
.qty-option.active {
  background: var(--accent);
  border-color: var(--accent);
}

.qty-dice {
  font-size: 1.4em;
  line-height: 1;
  letter-spacing: -2px;
}

.qty-label {
  font-size: 0.95em;
  font-weight: 700;
  color: var(--text);
}
.qty-option.active .qty-label {
  color: #fff;
}

/* ========================
   Mode Toggle
   ======================== */
.mode-row {
  display: flex;
  gap: 8px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-family: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.15s;
  color: var(--text);
  min-height: 52px;
}
.mode-btn:active { transform: scale(0.97); }
.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.mode-emoji { font-size: 1.1em; }

/* ========================
   Custom Faces
   ======================== */
.die-group {
  margin-bottom: 14px;
}
.die-group:last-child { margin-bottom: 0; }

.die-group-title {
  font-size: 0.82em;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.faces-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.face-input {
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  text-align: center;
  background: #faf8f6;
  transition: border-color 0.15s;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.face-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.face-input::placeholder {
  color: #c0b8b0;
  font-size: 0.9em;
}

/* ========================
   Go Button
   ======================== */
.go-btn {
  display: block;
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: 50px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 1.2em;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.15s;
  margin-bottom: 14px;
  min-height: 56px;
}
.go-btn:active {
  background: var(--accent-hover);
  transform: scale(0.98);
}
.go-btn.small {
  width: auto;
  padding: 12px 22px;
  font-size: 0.92em;
  display: inline-block;
  min-height: 44px;
}

/* ========================
   Dice Zone
   ======================== */
.dice-zone {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  padding: 16px 0;
}

.die-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.die-box:active .die-face {
  transform: scale(0.95);
}

.die-face {
  position: relative;
  width: 80px;
  height: 80px;
  background: #fff;
  border: 2.5px solid #222;
  border-radius: 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.1);
  transition: transform 0.15s;
}

.die-face.large  { width: 90px;  height: 90px; }
.die-face.medium { width: 76px;  height: 76px; }
.die-face.small  { width: 62px;  height: 62px; border-radius: 11px; }

.dots {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 12px;
}
.die-face.large .dots  { padding: 15px; }
.die-face.small .dots  { padding: 9px; }

.dot-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #222;
}
.die-face.large .dot  { width: 14px; height: 14px; }
.die-face.small .dot  { width: 9px;  height: 9px; }

.die-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1em;
  color: #222;
  text-align: center;
  padding: 6px;
  line-height: 1.15;
  word-break: break-word;
  overflow: hidden;
}
.die-face.small .die-text { font-size: 0.78em; padding: 4px; }
.die-face.large .die-text { font-size: 1.15em; }

.die-label {
  font-size: 0.7em;
  color: var(--text-soft);
  font-weight: 600;
  min-height: 1em;
}

/* ========================
   Animations
   ======================== */
.die-face.rolling {
  animation: roll 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
@keyframes roll {
  0%   { transform: rotate(0deg) scale(1); }
  15%  { transform: rotate(60deg) scale(0.88); }
  30%  { transform: rotate(150deg) scale(1.08); }
  50%  { transform: rotate(260deg) scale(0.9); }
  70%  { transform: rotate(400deg) scale(1.05); }
  85%  { transform: rotate(520deg) scale(0.95); }
  100% { transform: rotate(720deg) scale(1); }
}

.die-face.land {
  animation: land 0.25s ease;
}
@keyframes land {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ========================
   Results
   ======================== */
.sum-bar {
  text-align: center;
  margin-bottom: 14px;
  min-height: 20px;
}
.sum-badge {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 20px;
  background: #f0ece8;
  font-weight: 700;
  font-size: 0.9em;
}

/* ========================
   Actions
   ======================== */
.play-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.action-btn {
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-family: inherit;
  font-size: 0.8em;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.15s;
  color: var(--text);
  min-height: 44px;
}
.action-btn:active {
  background: #f0f0f0;
  transform: scale(0.97);
}

/* ========================
   History
   ======================== */
.history-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8em;
  gap: 8px;
}
.history-item:last-child { border-bottom: none; }

/* ========================
   Share Modal
   ======================== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.overlay.show { display: flex; }

.share-box {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 500px;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.share-box h2 { margin-bottom: 6px; font-size: 1.05em; }
.share-box p  { color: var(--text-soft); font-size: 0.82em; margin-bottom: 12px; }

.share-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  direction: ltr;
  text-align: left;
  margin-bottom: 12px;
  -webkit-appearance: none;
  appearance: none;
}
.share-input:focus { outline: none; border-color: var(--accent); }

.share-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ========================
   Toast
   ======================== */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--accent);
  color: #fff;
  padding: 10px 22px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.88em;
  transition: transform 0.3s;
  z-index: 200;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ========================
   Tablet+ (min 480px)
   ======================== */
@media (min-width: 480px) {
  .app {
    padding: 20px;
  }
  header {
    padding: 28px 0 24px;
  }
  .logo { font-size: 3em; }
  header h1 { font-size: 1.8em; }
  header p { font-size: 0.9em; }

  .card { padding: 20px; margin-bottom: 14px; }
  .card-label { font-size: 1em; }

  .faces-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .die-face.large  { width: 100px; height: 100px; }
  .die-face.medium { width: 86px;  height: 86px; }
  .die-face.small  { width: 70px;  height: 70px; }

  .die-face.large .dots  { padding: 18px; }
  .die-face.large .dot   { width: 15px; height: 15px; }
  .die-face.medium .dot  { width: 13px; height: 13px; }

  .dice-zone { gap: 20px; padding: 24px 0; }

  .go-btn { font-size: 1.15em; padding: 16px; }

  .mode-btn { font-size: 0.9em; padding: 14px 10px; }

  .overlay {
    align-items: center;
    padding: 20px;
  }
  .share-box {
    border-radius: var(--radius);
    padding: 28px;
    max-width: 420px;
    animation: none;
  }

  .action-btn { font-size: 0.82em; padding: 10px 16px; }
}

/* ========================
   Desktop (min 768px)
   ======================== */
@media (min-width: 768px) {
  .qty-btn:hover {
    border-color: var(--accent);
    background: #f0f0f0;
  }
  .mode-btn:hover { border-color: var(--accent); }
  .action-btn:hover { border-color: var(--accent); }
  .go-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
  }
  .die-box:hover .die-face { transform: translateY(-3px); }
}

/* ========================
   Small phones (max 360px)
   ======================== */
@media (max-width: 360px) {
  .app { padding: 8px; }
  header h1 { font-size: 1.3em; }
  .logo { font-size: 2.2em; }

  .die-face.large  { width: 78px;  height: 78px; }
  .die-face.medium { width: 66px;  height: 66px; }
  .die-face.small  { width: 54px;  height: 54px; border-radius: 9px; }

  .die-face.small .dot { width: 7px; height: 7px; }
  .die-face.small .dots { padding: 7px; }

  .dice-zone { gap: 10px; }
  .mode-btn { font-size: 0.78em; padding: 12px 6px; }
  .action-btn { font-size: 0.75em; padding: 10px 10px; }
}

/* ========================
   Landscape phone
   ======================== */
@media (max-height: 500px) and (orientation: landscape) {
  header { padding: 10px 0 8px; }
  .logo { font-size: 1.8em; }
  header h1 { font-size: 1.2em; }
  header p { display: none; }

  .dice-zone { padding: 10px 0; gap: 12px; }
  .die-face.large  { width: 72px; height: 72px; }
  .die-face.medium { width: 62px; height: 62px; }
  .die-face.small  { width: 52px; height: 52px; }

  .go-btn { padding: 12px; font-size: 1em; margin-bottom: 8px; }
  .card { padding: 12px; margin-bottom: 8px; }
}

/* ========================
   Static Page Content
   ======================== */
.page-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.page-card h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: #000;
}
.page-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 28px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
  color: #000;
}
.page-card p {
  font-size: 1em;
  line-height: 1.8;
  color: #444;
  margin-bottom: 12px;
}
.page-card a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.page-card ul {
  padding-right: 24px;
  margin: 8px 0 16px;
}
.page-card li {
  font-size: 1em;
  line-height: 1.8;
  color: #444;
  margin-bottom: 8px;
}
.page-date {
  font-size: 0.85em !important;
  color: var(--text-soft) !important;
}

/* ========================
   Ad Container
   ======================== */
.ad-container {
  margin: 16px 0;
  min-height: 50px;
}

/* ========================
   Footer
   ======================== */
.site-footer {
  margin-top: auto;
  padding: 32px 24px;
  padding-bottom: calc(32px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
}

.footer-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.footer-logo img {
  border-radius: 8px;
  opacity: 0.85;
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-bottom: 0;
}

.footer-links a {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85em;
  color: #888;
  text-decoration: none;
  font-weight: 600;
  line-height: 1.2;
  transition: color 0.2s;
}
.footer-links a:hover, 
.footer-links a:focus { 
  color: var(--accent); 
}

.footer-copy {
  font-size: 0.8em;
  color: #bbb;
  margin: 0;
}

/* ========================
   Skip Link
   ======================== */
.skip-link {
  position: absolute;
  top: -100%;
  right: 0;
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  z-index: 10000;
  border-radius: 0 0 0 8px;
  font-weight: 700;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* ========================
   Header Link (eduplays)
   ======================== */
.header-link {
  color: #2d6a4f;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 8px 16px;
  border: 1.5px solid #2d6a4f;
  border-radius: 20px;
  transition: background 0.2s, color 0.2s;
}
.header-link:hover {
  background: #2d6a4f;
  color: #fff;
}

@media (max-width: 480px) {
  .header-link {
    font-size: 0.75em;
    padding: 6px 12px;
  }
}

/* ========================
   Accessibility Widget
   ======================== */
#accessibility-widget {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9998;
}

#acc-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: transform 0.2s, background 0.2s;
  cursor: pointer;
}
#acc-toggle:hover {
  transform: scale(1.1);
  background: var(--accent-hover);
}

.acc-panel {
  position: absolute;
  bottom: 56px;
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 170px;
  animation: accFadeUp 0.2s ease;
}

@keyframes accFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.acc-panel-title {
  font-size: 0.95em;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.acc-option {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.82em;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: right;
  transition: background 0.2s, border-color 0.2s;
}
.acc-option:hover {
  background: #eee;
  border-color: var(--accent);
}

/* Accessibility Modes */
body.acc-high-contrast {
  --bg: #000;
  --card: #1a1a1a;
  --text: #fff;
  --text-soft: #ffff00;
  --border: #ffff00;
  --accent: #00ff00;
  --accent-hover: #009900;
}
body.acc-high-contrast .app-header {
  background: #1a1a1a;
  border-bottom-color: #ffff00;
}
body.acc-high-contrast .site-footer {
  background: #1a1a1a;
}

body.acc-underline-links a {
  text-decoration: underline !important;
  text-underline-offset: 3px;
}

body.acc-readable-font,
body.acc-readable-font * {
  font-family: Arial, Helvetica, sans-serif !important;
  letter-spacing: 0.02em;
}
/* ===================== */
/* Sidebar Ads           */
/* ===================== */
.ad-sidebar {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-sidebar-right { right: 8px; }
.ad-sidebar-left  { left: 8px;  }

@media (max-width: 1460px) {
    .ad-sidebar-right { right: 4px; }
    .ad-sidebar-left  { left: 4px;  }
}

@media (max-width: 1320px) {
    .ad-sidebar { display: none; }
}
