:root {
  --primary: #1a5d48;
  --primary-light: #e8f3ef;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --radius: clamp(16px, 2.5vmin, 32px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg);
}

body {
  margin: 0; padding: 0;
  width: 100vw; 
  height: 100vh;
  max-width: 1080px;
  max-height: 1920px;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
}

/* Screensaver Animation */
.screensaver-bg {
  position: fixed; inset: 0;
  background: linear-gradient(-45deg, #1a5d48, #2d8a6c, #164e3c, #1a5d48);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; color: white;
  text-decoration: none;
}

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Layouts */
.container {
  width: 100%; height: 100%;
  padding: clamp(24px, 3.5vmin, 68px);
  display: flex; flex-direction: column;
}

.lang-card {
  background: rgba(255,255,255,0.85);
  width: clamp(200px, 42vmin, 460px); 
  height: clamp(260px, 52vmin, 580px);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px 0 rgba(26,93,72,0.18), 0 1.5px 8px 0 rgba(0,0,0,0.10);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-decoration: none; color: var(--primary);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, border-color 0.3s ease;
  border: 2px solid rgba(26,93,72,0.10);
  position: relative;
  overflow: hidden;
}
.lang-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(26,93,72,0.08) 0%, rgba(0,0,0,0.03) 100%);
  z-index: 0;
}
.lang-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(26,93,72,0.08);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 1;
}
.lang-card:active::after {
  opacity: 1;
  transition: opacity 0s;
}
.lang-card > * { position: relative; z-index: 2; }
.lang-card:active, .lang-card:focus {
  transform: scale(0.95);
  box-shadow: 0 4px 16px 0 rgba(26,93,72,0.25);
  border-color: var(--primary);
}
.lang-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 50px 0 rgba(26,93,72,0.25), 0 4px 16px 0 rgba(0,0,0,0.15);
  border-color: var(--primary);
}

.topics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(16px, 2.2vmin, 43px);
  flex-grow: 1;
}

.topic-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(232,243,239,0.9) 100%);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px 0 rgba(26,93,72,0.15), 0 2px 12px 0 rgba(0,0,0,0.08);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: clamp(16px, 1.7vmin, 32px) clamp(14px, 1.4vmin, 27px); text-align: center;
  font-size: clamp(18px, 1.8vmin, 35px); font-weight: 700;
  color: var(--primary);
  border: none;
  border-bottom: clamp(3px, 0.26vmin, 5px) solid var(--primary);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, background 0.3s ease;
}
.topic-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(26,93,72,0.06);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 0;
}
.topic-card:hover::before {
  opacity: 1;
}
.topic-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: clamp(3px, 0.4vmin, 6px);
  background: linear-gradient(90deg, var(--primary), #2d8a6c, var(--primary));
  background-size: 200% 100%;
  animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.topic-card .icon {
  font-size: clamp(32px, 3.4vmin, 65px);
  margin-bottom: clamp(8px, 0.8vmin, 16px);
  filter: drop-shadow(0 2px 4px rgba(26,93,72,0.2));
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 1;
}
.topic-card .label { position: relative; z-index: 1; }
.topic-card:hover .icon { transform: scale(1.2) rotate(8deg); }
.topic-card:active, .topic-card:focus {
  background: linear-gradient(135deg, var(--primary-light) 0%, rgba(232,243,239,1) 100%);
  transform: scale(0.94);
  box-shadow: 0 4px 16px 0 rgba(26,93,72,0.2);
}
.topic-card:hover {
  transform: translateY(-8px) scale(1.03);
  box-shadow: 0 20px 50px 0 rgba(26,93,72,0.25), 0 6px 20px 0 rgba(0,0,0,0.12);
}
/* Back button modernized */
.back-nav {
  background: linear-gradient(90deg, var(--primary-light) 60%, #fff 100%);
  color: var(--primary);
  border: none;
  padding: clamp(12px, 1.25vmin, 24px) clamp(26px, 2.7vmin, 51px);
  border-radius: 50px;
  font-weight: 700;
  text-decoration: none;
  font-size: clamp(16px, 1.6vmin, 30px);
  box-shadow: 0 4px 12px 0 rgba(26,93,72,0.12);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, background 0.3s ease;
  position: relative;
  overflow: hidden;
}
.back-nav::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}
.back-nav:hover::after {
  transform: translateX(100%);
}
.back-nav:active, .back-nav:focus {
  transform: scale(0.95);
  box-shadow: 0 2px 6px 0 rgba(26,93,72,0.15);
}
.back-nav:hover {
  transform: translateX(-4px);
  box-shadow: 0 6px 20px 0 rgba(26,93,72,0.18);
  background: var(--primary-light);
}

/* RTL Support */
.rtl {
  direction: rtl;
  text-align: right;
}

.rtl .topic-card {
  text-align: center;
}
.rtl .topic-card:hover .icon { transform: scale(1.2) rotate(-8deg); }

.rtl .lang-card {
  text-align: right;
}

.rtl .modal-content {
  text-align: right;
}

/* Modal overlay and content improvements */
.modal-overlay {
  background: rgba(0,0,0,0.6) !important;
}
.modal-content {
  box-shadow: 0 12px 48px 0 rgba(26,93,72,0.18), 0 2px 12px 0 rgba(0,0,0,0.10) !important;
  border-radius: clamp(20px, 3vmin, 40px) !important;
  border: 1.5px solid rgba(26,93,72,0.10) !important;
  background: #fff !important;
}

/* ===========================================
   RESPONSIVE BREAKPOINTS
   Kiosk (1080x1920) uses vmin values above.
   These overrides fix tablets and phones.
   =========================================== */

/* TABLET - Portrait (600px - 900px width) */
@media screen and (max-width: 900px) {
  :root {
    --radius: 20px;
  }
  
  body {
    max-width: 100%;
    max-height: 100%;
    overflow-y: auto;
  }
  
  .container {
    padding: 24px;
  }
  
  /* Screensaver */
  .title-main {
    font-size: 48px;
  }
  .title-sub {
    font-size: 28px;
  }
  .touch-icon-wrapper {
    width: 80px;
    height: 80px;
  }
  .touch-icon svg {
    width: 40px;
    height: 40px;
  }
  .touch-label {
    font-size: 16px;
  }
  
  /* Language cards - side by side but smaller */
  .lang-card {
    width: 42vw;
    height: 55vw;
    max-width: 280px;
    max-height: 360px;
  }
  
  .lang-card div:first-child {
    font-size: 48px !important;
  }
  
  .lang-card h2 {
    font-size: 22px !important;
  }
  
  .lang-card p {
    font-size: 14px !important;
  }
  
  /* Topics grid - 2 columns still works */
  .topics-grid {
    gap: 16px;
    grid-template-rows: repeat(3, minmax(120px, 1fr));
  }
  
  .topic-card {
    font-size: 16px;
    padding: 16px 12px;
    border-bottom-width: 3px;
  }
  
  .topic-card .icon {
    font-size: 32px;
    margin-bottom: 8px;
  }
  
  /* Back button */
  .back-nav {
    font-size: 15px;
    padding: 12px 20px;
  }
  
  /* Modal */
  .modal-content {
    width: 90vw !important;
    max-width: 500px !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    padding: 24px !important;
    border-radius: 20px !important;
  }
}

/* PHONE - Portrait (max 600px width) */
@media screen and (max-width: 600px) {
  :root {
    --radius: 16px;
  }
  
  body {
    overflow-y: auto;
  }
  
  .container {
    padding: 16px;
    height: auto;
    min-height: 100vh;
  }
  
  /* Screensaver */
  .title-main {
    font-size: 36px;
  }
  .title-sub {
    font-size: 22px;
  }
  .touch-icon-wrapper {
    width: 60px;
    height: 60px;
  }
  .touch-icon svg {
    width: 32px;
    height: 32px;
  }
  .touch-label {
    font-size: 14px;
  }
  
  /* Language cards - STAY SIDE BY SIDE but smaller */
  .lang-card {
    width: 44vw;
    max-width: 180px;
    height: auto;
    min-height: 200px;
    padding: 20px 12px;
  }
  
  .lang-card div:first-child {
    font-size: 36px !important;
    margin-bottom: 8px !important;
  }
  
  .lang-card h2 {
    font-size: 18px !important;
  }
  
  .lang-card p {
    font-size: 11px !important;
  }
  
  /* Topics grid - SINGLE COLUMN on phones */
  .topics-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 12px;
  }
  
  .topic-card {
    font-size: 15px;
    padding: 16px;
    min-height: 90px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 16px;
    text-align: left;
  }
  
  .topic-card .icon {
    font-size: 28px;
    margin-bottom: 0;
  }
  
  .topic-card .label {
    flex: 1;
  }
  
  .rtl .topic-card {
    text-align: right;
  }
  
  /* Back button */
  .back-nav {
    font-size: 14px;
    padding: 10px 16px;
  }
  
  /* Modal - full width on phone */
  .modal-content {
    width: 95vw !important;
    max-width: none !important;
    max-height: 90vh !important;
    padding: 20px !important;
    border-radius: 16px !important;
    margin: 16px !important;
  }
  
  /* Modal responsive text */
  .qr-img {
    width: 140px !important;
  }
  
  .store-badge {
    width: 120px !important;
  }
}

/* Very small phones (max 380px) */
@media screen and (max-width: 380px) {
  .title-main {
    font-size: 30px;
  }
  .title-sub {
    font-size: 18px;
  }
  .touch-icon-wrapper {
    width: 50px;
    height: 50px;
  }
  .touch-icon svg {
    width: 28px;
    height: 28px;
  }
  .touch-label {
    font-size: 12px;
  }
  
  /* Language cards - even smaller but still side by side */
  .lang-card {
    width: 46vw;
    max-width: 160px;
    min-height: 180px;
    padding: 16px 10px;
  }
  
  .lang-card div:first-child {
    font-size: 30px !important;
  }
  
  .lang-card h2 {
    font-size: 16px !important;
  }
  
  .lang-card p {
    font-size: 10px !important;
  }
  
  .topic-card {
    font-size: 14px;
    padding: 14px;
    min-height: 80px;
  }
  
  .topic-card .icon {
    font-size: 24px;
  }
}

/* Landscape phones - ensure usability */
@media screen and (max-height: 500px) and (orientation: landscape) {
  body {
    overflow-y: auto;
  }
  
  .container {
    height: auto;
    min-height: 100vh;
  }
  
  .screensaver-bg {
    position: relative;
    min-height: 100vh;
  }
  
  .lang-card {
    height: auto;
    min-height: 140px;
  }
  
  .topics-grid {
    grid-template-rows: auto;
  }
}