:root{
  --bg:#fafafa;
  --card:#fff;
  --muted:#666;
  --accent:#0b6efd;
  --shadow: 0 6px 18px rgba(12,18,29,0.08);
  --radius:12px;
  --gap:12px;
}

*{box-sizing:border-box}
html,body,#app{height:100%}
body{
  margin:0;
  font-family:Inter,system-ui,Segoe UI,Roboto,"Helvetica Neue",Arial;
  background:var(--bg);
  color:#0b1220;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}

#app{
  display:flex;
  flex-direction:column;
  gap:var(--gap);
  padding:14px;
  height:100vh;
}

#header{
  display:flex;
  gap:12px;
  align-items:center;
}
#brand{
  font-weight:600;
  font-size:16px;
}
#search{
  flex:1;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid #e6e9ee;
  background:#fff;
  font-size:14px;
  min-height:44px;
}

#grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:12px;
  margin-top:2px;
  align-content:start;
}

/* Flag card */
.card{
  background:var(--card);
  border-radius:12px;
  padding:10px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
  box-shadow:var(--shadow);
  min-height:92px;
  justify-content:center;
  cursor:pointer;
  transition:transform .12s ease, box-shadow .12s ease;
}
.card:active{transform:translateY(1px)}
.card svg{width:100%; height:44px; display:block; border-radius:6px; overflow:hidden;}

/* name */
.cname{
  font-size:12px;
  color:var(--muted);
  text-align:center;
  width:100%;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  padding:0 4px;
}

/* viewer overlay (bottom sheet style) */
#viewer{
  position:fixed;
  left:12px;
  right:12px;
  bottom:14px;
  background:var(--card);
  border-radius:14px;
  padding:12px;
  box-shadow:0 20px 40px rgba(10,14,20,0.12);
  transform:translateY(110%);
  transition:transform .25s cubic-bezier(.2,.9,.2,1);
  z-index:60;
  max-height:72%;
  overflow:auto;
}
#viewer.open{transform:translateY(0%)}

#viewer-inner{display:flex;gap:12px;align-items:center}
#preview{width:40%; min-width:120px; display:flex; align-items:center; justify-content:center;}
#preview svg{width:100%; height:auto; max-height:160px; border-radius:8px; box-shadow:var(--shadow)}
#meta{flex:1; display:flex; flex-direction:column; gap:8px}
#country-name{font-weight:700}
#actions{display:flex;gap:8px}
#actions button, #actions a{
  background:var(--accent);
  color:#fff;
  padding:8px 12px;
  border-radius:10px;
  text-decoration:none;
  border:none;
  font-weight:600;
  font-size:13px;
  display:inline-flex;
  align-items:center;
  gap:8px;
  min-height:44px;
}
#actions a{background:#0b6efdcc}
#close{
  position:absolute;
  right:18px;
  top:8px;
  background:transparent;
  border:none;
  font-size:18px;
  color:var(--muted);
  padding:8px;
}

#foot{
  font-size:12px;
  color:var(--muted);
  text-align:center;
  padding:6px 0;
}

/* Responsive adjustments for mobile viewport (single-screen) */
@media (max-width:520px){
  #grid{grid-template-columns:repeat(3,1fr); gap:10px}
  #viewer-inner{flex-direction:column;align-items:stretch}
  #preview{width:100%}
  #actions{flex-direction:row; justify-content:space-between}
}