/*
Theme Name: Mangmee 889 Green Gold
Author: Mangmee 889
Description: หน้าแรกหมวดหวย สีเขียวมรกตและทอง ออกแบบสำหรับมั่งมี889
Version: 1.0.0
Requires at least: 6.0
Requires PHP: 7.4
Text Domain: mangmee889
*/
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800;900&display=swap');
:root{--gold:#e4bc58;--cream:#ffedba;--green:#00643d;--deep:#002b20;--line:#b68f3f}*{box-sizing:border-box}html{scroll-behavior:smooth}body{margin:0;background:#003323;color:#fff8e8;font-family:'Noto Sans Thai',Tahoma,sans-serif;font-size:16px}a{color:inherit;text-decoration:none}button{font:inherit;cursor:pointer}button,a{-webkit-tap-highlight-color:transparent}button:focus-visible,a:focus-visible{outline:3px solid #fff1bb;outline-offset:4px}.skip{position:absolute;top:-100px}.skip:focus{top:5px;left:5px;z-index:20;background:#fff;color:#002b20;padding:12px}.site-header{height:88px;display:flex;align-items:center;justify-content:space-between;padding:6px 30px;background:linear-gradient(100deg,#005c3d,#008258 48%,#004a32);border:1px solid var(--gold);box-shadow:0 8px 30px #0005;position:relative;z-index:3}.brand{display:flex;align-items:center}.brand img{width:210px;height:76px;object-fit:contain}.header-actions{display:flex;gap:15px;align-items:center}.btn{border:1px solid #ffffff38;color:#fff8e7;background:linear-gradient(#087c53,#005a3b);border-radius:12px;padding:10px 28px;font-weight:800;display:inline-flex;justify-content:center;align-items:center;gap:8px;min-height:44px}.btn.gold{background:linear-gradient(110deg,#d3a02e,#ffedb0 48%,#deb13f);color:#143b24;border:1px solid #f7d67a;box-shadow:0 4px 14px #0002}.header-actions .login{background:none;border-color:transparent}.stage{position:relative;min-height:calc(100vh - 88px);isolation:isolate;overflow:hidden}.stage:before{content:'';position:absolute;inset:0;z-index:-2;background:radial-gradient(ellipse at 65% 10%,#08714b66,transparent 65%),linear-gradient(120deg,#002d20e8,#003825a0),url('assets/pattern.svg') center/630px}.stage:after{content:'';position:absolute;inset:0;z-index:-1;background:linear-gradient(180deg,transparent 65%,#00291ddd);pointer-events:none}.shell{display:grid;grid-template-columns:280px minmax(0,1fr);gap:28px;padding:16px 18px 36px;max-width:1920px;margin:auto}.sidebar{border:1px solid var(--gold);background:linear-gradient(155deg,#00603bea,#003c2bf2);border-radius:18px;padding:14px;height:fit-content;min-height:700px;box-shadow:0 14px 40px #001a1570}.welcome{background:#ffffff08;border:1px solid #ffffff1f;border-radius:14px;padding:17px 12px;display:flex;align-items:center;gap:12px;font-size:19px;font-weight:800;margin-bottom:12px}.user-icon{border:1px solid #d8c07d70;width:46px;height:46px;display:grid;place-items:center;border-radius:50%;color:var(--cream);font-size:26px}.side-actions{display:grid;gap:8px;margin-bottom:16px}.side-actions .btn{padding:7px;min-height:39px}.side-nav{display:grid;gap:9px}.side-link{display:flex;gap:13px;align-items:center;padding:9px 12px;min-height:64px;border:1px solid #c7a65155;border-radius:14px;font-size:18px;font-weight:800;background:#00432c70;transition:.2s}.side-link img{width:42px;height:42px}.side-link.active{background:linear-gradient(100deg,#d4a32f,#ffecb0 50%,#d7aa38);color:#193d23;border-color:#f4d276}.side-link:hover{transform:translateX(3px);border-color:#f8d580}.side-caption{font-size:12px;letter-spacing:2px;color:#d8c992;margin:24px 5px 10px}.side-note{padding:18px 8px;color:#b7cbb8;font-size:12px;line-height:1.9}.side-seal{margin:28px auto 0;width:116px;height:116px;border:1px solid #cda84966;border-radius:50%;display:grid;place-content:center;text-align:center;outline:1px solid #cda84930;outline-offset:7px;color:#e4c46d}.side-seal strong{font-size:37px;line-height:1.1;font-weight:900}.side-seal span{font-size:10px;letter-spacing:3px}.main{min-width:0;padding-top:6px}.category-nav{display:grid;grid-template-columns:repeat(4,minmax(110px,145px));gap:12px;margin-bottom:29px}.category{border:1px solid var(--gold);border-radius:20px;background:linear-gradient(160deg,#0c7952,#00412d 85%);display:flex;flex-direction:column;align-items:center;justify-content:center;height:146px;font-size:19px;font-weight:900;position:relative;box-shadow:inset 0 1px 0 #ffffff15,0 8px 14px #0002;transition:transform .2s}.category img{width:82px;height:82px;margin-bottom:5px;filter:drop-shadow(0 5px 5px #001d1a80)}.category.active{border:3px solid #ffedbd;box-shadow:0 0 0 4px #c6a243,0 0 24px #f8d26445;background:linear-gradient(155deg,#13a66a,#006641)}.category.active span{background:linear-gradient(#e6bf5e,#cf9d30);color:#16391f;border-radius:18px;padding:0 16px}.category:hover{transform:translateY(-3px)}.content-title{display:flex;align-items:center;justify-content:space-between;margin:0 0 15px}.content-title h1{font-size:25px;margin:0;font-weight:900}.content-title p{font-size:12px;color:#c4d9c7;margin:0}.lotto-section{scroll-margin-top:20px;margin-bottom:24px}.section-heading{display:flex;align-items:center;gap:16px;margin:0 0 14px;font-size:19px}.section-heading span{display:block;background:linear-gradient(115deg,#cba032,#fff0ba,#d2aa3b);border:1px solid #edcc73;color:#183b25;border-radius:7px;padding:4px 12px;box-shadow:0 3px 10px #0002;font-weight:900}.section-heading:after{content:'';height:1px;background:linear-gradient(90deg,#d0aa52,#d0aa5200);flex:1}.lotto-grid{display:flex;flex-wrap:wrap;gap:12px;padding:0 8px}.lotto-card{width:248px;min-height:96px;border:1px solid #d6ab43;border-radius:30px;display:flex;align-items:center;gap:12px;padding:12px 17px;background:linear-gradient(130deg,#08754c,#005034 75%);box-shadow:inset 0 1px 0 #ffffff12,0 8px 18px #001b192b;color:#fff;transition:.2s;text-align:left}.lotto-card:hover{border-color:#fff0b6;transform:translateY(-3px);background:linear-gradient(130deg,#11875a,#005a3c)}.lotto-card img{width:61px;height:61px;border-radius:50%;border:2px solid #f0d189;box-shadow:0 2px 6px #0005;flex:none}.lotto-card strong{display:block;font-size:18px;font-weight:900;white-space:nowrap}.round{margin-top:4px;border-radius:20px;background:#f7f6e8;color:#174332;display:inline-flex;gap:5px;align-items:center;padding:2px 10px 2px 5px;font-size:12px;font-weight:700}.clock{border:2px solid #174332;border-radius:50%;width:18px;height:18px;display:inline-block;position:relative}.clock:before{content:'';position:absolute;left:7px;top:2px;height:6px;width:2px;background:#174332}.clock:after{content:'';position:absolute;left:7px;top:7px;height:2px;width:5px;background:#174332}.page-note{color:#bed0bc;font-size:12px;margin:30px 8px;display:flex;gap:10px;align-items:center}.page-note:before{content:'';width:6px;height:6px;background:#d7ba64;border-radius:50%}.site-footer{display:flex;align-items:center;justify-content:space-between;margin:45px 8px 0;border-top:1px solid #d4af5333;padding-top:18px;color:#a9c3b0;font-size:12px}.site-footer b{color:#e1c779;font-size:16px}.mobile-nav{display:none}dialog{border:1px solid var(--gold);border-radius:22px;padding:30px;background:linear-gradient(135deg,#00613f,#002e23);color:#fff7dc;width:min(430px,calc(100% - 32px));box-shadow:0 20px 90px #0008}dialog::backdrop{background:#001a14c9;backdrop-filter:blur(5px)}dialog h2{margin-top:0;color:#ffe6a1}dialog p{line-height:1.9;color:#d5e5d8}.dialog-close{float:right;background:none;border:0;color:#ffe8aa;font-size:26px;padding:0 5px}.dialog-ok{width:100%;margin-top:12px}body.admin-bar .stage{min-height:calc(100vh - 120px)}
@media(min-width:1600px){.shell{grid-template-columns:320px minmax(0,1fr);gap:36px}.sidebar{min-height:790px}.category-nav{grid-template-columns:repeat(4,155px)}.category{height:150px}.lotto-card{width:265px}}
@media(max-width:1000px){.shell{grid-template-columns:220px minmax(0,1fr);gap:20px;padding:16px 12px}.sidebar{padding:11px}.side-link{font-size:16px}.category-nav{gap:10px;grid-template-columns:repeat(4,minmax(0,1fr))}.category{height:126px;font-size:16px}.category img{width:69px;height:69px}.lotto-card{width:calc(50% - 6px);padding:12px;border-radius:24px;gap:9px}.lotto-card img{width:48px;height:48px}.lotto-card strong{font-size:15px}.content-title{align-items:flex-start;gap:10px}.content-title p{max-width:140px;text-align:right}}
@media(max-width:700px){.site-header{height:76px;padding:4px 13px}.brand img{width:157px;height:66px}.header-actions{gap:4px}.header-actions .btn{font-size:12px;padding:8px 12px;min-height:38px;border-radius:9px}.header-actions .login{padding:8px}.shell{display:block;padding:18px 14px 80px}.sidebar{display:none}.main{padding-top:3px}.category-nav{gap:10px;margin:0 3px 26px}.category{height:112px;border-radius:16px;font-size:14px}.category img{width:64px;height:64px}.category.active span{padding:0 10px}.content-title h1{font-size:22px}.content-title p{font-size:10px;max-width:140px}.section-heading{font-size:16px;gap:10px;margin-bottom:11px}.lotto-grid{padding:0;gap:10px}.lotto-card{width:calc(50% - 5px);min-height:86px;padding:10px 8px;gap:7px;border-radius:22px}.lotto-card img{width:43px;height:43px}.lotto-card strong{font-size:13px}.round{font-size:10px;padding-right:7px}.clock{width:15px;height:15px}.clock:before{left:5px;top:2px;height:5px}.clock:after{left:5px;top:6px;width:4px}.lotto-section{margin-bottom:22px}.site-footer{margin-top:30px;gap:10px;align-items:start}.site-footer span{max-width:160px;text-align:right;font-size:10px}.mobile-nav{display:flex;position:fixed;bottom:0;left:0;right:0;background:#003c2df5;backdrop-filter:blur(16px);border-top:1px solid #caab55;z-index:5;justify-content:space-around;padding:8px 8px max(8px,env(safe-area-inset-bottom))}.mobile-nav a,.mobile-nav button{background:none;border:0;color:#e3d5a2;font-size:11px;display:flex;flex-direction:column;align-items:center;gap:3px;min-width:65px}.mobile-nav i{font-style:normal;font-size:20px;line-height:1.2}.mobile-nav .selected{color:#ffe6a1}.stage{min-height:calc(100vh - 76px)}}
@media(prefers-reduced-motion:reduce){html{scroll-behavior:auto}*{transition:none!important}}

/* Equal icon and label rows for every mobile navigation item. */
@media(max-width:700px){
  .mobile-nav{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));align-items:stretch;gap:0}
  .mobile-nav>a,.mobile-nav>button{display:grid;grid-template-rows:24px 20px;justify-items:center;align-items:center;align-content:center;gap:4px;min-width:0;width:100%;min-height:48px;margin:0;padding:0 2px;line-height:20px;white-space:nowrap;font-weight:500}
  .mobile-nav i{display:grid;place-items:center;width:24px;height:24px;font-size:20px;line-height:24px}
  .mobile-nav>:nth-child(3)::before,.mobile-nav>:nth-child(4)::before{content:'';display:block;width:24px;height:24px;background:currentColor;mask:center/22px 22px no-repeat;-webkit-mask:center/22px 22px no-repeat}
  .mobile-nav>:nth-child(3)::before{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3Cpath d='M4 21v-2a8 8 0 0 1 16 0v2'/%3E%3C/svg%3E");-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3Cpath d='M4 21v-2a8 8 0 0 1 16 0v2'/%3E%3C/svg%3E")}
  .mobile-nav>:nth-child(4)::before{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round'%3E%3Cpath d='M21 11a9 9 0 0 1-9 9H4l-2 2V11a9 9 0 0 1 19 0Z'/%3E%3Cpath d='M7 10h10M7 14h7'/%3E%3C/svg%3E");-webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round'%3E%3Cpath d='M21 11a9 9 0 0 1-9 9H4l-2 2V11a9 9 0 0 1 19 0Z'/%3E%3Cpath d='M7 10h10M7 14h7'/%3E%3C/svg%3E")}
}


/* Native menus, editable palette, and standard WordPress homepage selection. */
add_action('after_setup_theme', function(){
    register_nav_menus(array('mm889_sidebar'=>'เมนูซ้าย — คอมพิวเตอร์','mm889_mobile'=>'เมนูล่าง — มือถือ'));
});
function mm889_lottery_view(){
    $page=(int)get_theme_mod('mm889_lottery_page',0);
    return ($page && is_page($page)) || (is_front_page() && get_option('show_on_front')!=='page');
}
function mm889_lottery_base(){
    $page=(int)get_theme_mod('mm889_lottery_page',0);
    if(get_option('show_on_front')!=='page' || (int)get_option('page_on_front')===$page){return home_url('/');}
    return $page && get_post_status($page)==='publish' ? get_permalink($page) : home_url('/');
}
function mm889_menu_icons(){return array('home'=>'หน้าหลัก','lotto'=>'หวย','thai'=>'สลากไทย','four'=>'4D','stock'=>'หุ้น','user'=>'สมาชิก','chat'=>'ติดต่อ','star'=>'ดาว','book'=>'บทความ','link'=>'ลิงก์');}
function mm889_menu_icon($key){
    if(in_array($key,array('lotto','thai','four','stock'),true)){return '<img src="'.esc_url(get_template_directory_uri().'/assets/'.$key.'.svg').'" alt="">';}
    $paths=array('home'=>'<path d="m3 10 9-7 9 7v11h-7v-7h-4v7H3z"/>','user'=>'<circle cx="12" cy="7" r="4"/><path d="M4 22v-3a8 8 0 0 1 16 0v3"/>','chat'=>'<path d="M21 11a9 9 0 0 1-9 9H5l-3 2V11a9 9 0 0 1 19 0Z"/><path d="M7 9h10M7 13h7"/>','star'=>'<path d="m12 2 3 6 7 1-5 5 1 8-6-4-6 4 1-8-5-5 7-1z"/>','book'=>'<path d="M3 4h7l2 2 2-2h7v16h-7l-2 2-2-2H3zM12 6v16"/>','link'=>'<path d="m9 15 6-6M8 17l-2 2a4 4 0 0 1-6-6l5-5a4 4 0 0 1 6 0M16 7l2-2a4 4 0 0 1 6 6l-5 5a4 4 0 0 1-6 0" transform="translate(1 -1) scale(.9)"/>');
    return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">'.($paths[$key]??$paths['link']).'</svg>';
}
function mm889_render_menu($location){
    $locations=get_nav_menu_locations();$items=isset($locations[$location])?wp_get_nav_menu_items($locations[$location]):array();
    if(!$items){return;}
    foreach($items as $item){
        if($item->type==='post_type' && get_post_status($item->object_id)!=='publish'){continue;}
        $role=get_post_meta($item->ID,'_mm889_role',true);$anchor=get_post_meta($item->ID,'_mm889_anchor',true);$url=$item->url;
        if(in_array($role,array('login','register','contact'),true)){$url=get_theme_mod('mm889_'.$role,'');}
        if($role==='lottery' && in_array($anchor,array('main','thai','lao','hanoi','four','stock'),true)){$url=mm889_lottery_base().'#'.$anchor;}
        $icon=get_post_meta($item->ID,'_mm889_icon',true)?:'link';$look=get_post_meta($item->ID,'_mm889_look',true);
        $class=$location==='mm889_sidebar'?'side-link':'mm-mobile-item';if($look==='gold'){$class.=' mm-menu-gold';}
        $attrs=$item->target==='_blank'?' target="_blank" rel="noopener noreferrer"':'';
        $inside='<span class="mm-menu-icon">'.mm889_menu_icon($icon).'</span><span class="mm-menu-label">'.esc_html($item->title).'</span>';
        if($url){echo '<a class="'.esc_attr($class).'" href="'.esc_url($url).'"'.$attrs.'>'.$inside.'</a>';}
        else{echo '<button type="button" class="'.esc_attr($class).'" data-notice="'.esc_attr($item->title).'">'.$inside.'</button>';}
    }
}
add_action('wp_nav_menu_item_custom_fields',function($id,$item){
    echo '<p class="description description-wide"><label>ไอคอนปุ่ม<br><select name="mm889_icon['.absint($id).']">';foreach(mm889_menu_icons() as $key=>$label){echo '<option value="'.esc_attr($key).'" '.selected(get_post_meta($id,'_mm889_icon',true),$key,false).'>'.esc_html($label).'</option>';}echo '</select></label></p>';
    echo '<p class="description description-wide"><label>รูปแบบปุ่ม<br><select name="mm889_look['.absint($id).']"><option value="normal">ปกติ</option><option value="gold" '.selected(get_post_meta($id,'_mm889_look',true),'gold',false).'>สีเน้น / ทอง</option></select></label></p>';
    echo '<p class="description description-wide"><label>แหล่งลิงก์<br><select name="mm889_role['.absint($id).']">';foreach(array('custom'=>'ใช้ URL / หน้าที่เลือกในเมนูนี้','login'=>'ใช้ลิงก์เข้าสู่ระบบส่วนกลาง','register'=>'ใช้ลิงก์สมัครสมาชิกส่วนกลาง','contact'=>'ใช้ลิงก์ติดต่อส่วนกลาง','lottery'=>'ไปยังหมวดในหน้ารวมหวย') as $key=>$label){echo '<option value="'.esc_attr($key).'" '.selected(get_post_meta($id,'_mm889_role',true)?:'custom',$key,false).'>'.esc_html($label).'</option>';}echo '</select></label></p>';
    echo '<p class="description description-wide"><label>หมวดปลายทาง (เมื่อเลือกไปยังหมวดในหน้ารวมหวย)<br><select name="mm889_anchor['.absint($id).']">';foreach(array('main'=>'ทั้งหมด','thai'=>'ไทย','lao'=>'ลาว','hanoi'=>'ฮานอย','four'=>'4D','stock'=>'หุ้น') as $key=>$label){echo '<option value="'.esc_attr($key).'" '.selected(get_post_meta($id,'_mm889_anchor',true),$key,false).'>'.esc_html($label).'</option>';}echo '</select></label></p><p class="description description-wide">ต้องการเปลี่ยน URL เอง ให้เลือกแหล่งลิงก์ “ใช้ URL / หน้าที่เลือกในเมนูนี้”</p>';
},10,2);
add_action('wp_update_nav_menu_item',function($menu,$id){
    if(!current_user_can('edit_theme_options')){return;}
    $allowed=array('icon'=>array_keys(mm889_menu_icons()),'look'=>array('normal','gold'),'role'=>array('custom','login','register','contact','lottery'),'anchor'=>array('main','thai','lao','hanoi','four','stock'));
    foreach($allowed as $field=>$values){if(isset($_POST['mm889_'.$field][$id])){$value=sanitize_key(wp_unslash($_POST['mm889_'.$field][$id]));if(in_array($value,$values,true)){update_post_meta($id,'_mm889_'.$field,$value);}}}
},10,2);
add_action('init',function(){
    if(get_option('mm889_flexible_setup_v1')){return;}
    $page=wp_insert_post(array('post_type'=>'page','post_title'=>'รายการหวย','post_name'=>'lottery','post_status'=>'publish','post_content'=>'หน้ารวมรายการหวย แบนเนอร์ และลิงก์แนะนำของเว็บไซต์'));
    if(is_wp_error($page)||!$page){return;}set_theme_mod('mm889_lottery_page',$page);
    $definitions=array('mm889_sidebar'=>array('เมนูซ้าย คอมพิวเตอร์',array(array('เข้าสู่ระบบ','user','login','normal',''),array('สมัครสมาชิก','user','register','gold',''),array('หวยทั้งหมด','lotto','lottery','gold','main'),array('หวยไทย','thai','lottery','normal','thai'),array('หวยลาว','lotto','lottery','normal','lao'),array('หวยฮานอย','four','lottery','normal','hanoi'),array('หวย 4D','four','lottery','normal','four'),array('หวยหุ้น','stock','lottery','normal','stock'),array('ติดต่อทีมงาน','chat','contact','normal',''))),'mm889_mobile'=>array('เมนูล่าง มือถือ',array(array('หน้าหวย','home','lottery','normal','main'),array('หวยไทย','book','lottery','normal','thai'),array('เข้าสู่ระบบ','user','login','normal',''),array('ติดต่อทีมงาน','chat','contact','normal',''))));
    $locations=get_nav_menu_locations();foreach($definitions as $location=>$definition){if(!empty($locations[$location])){continue;}$menu=wp_create_nav_menu($definition[0]);if(is_wp_error($menu)){continue;}foreach($definition[1] as $n=>$row){$id=wp_update_nav_menu_item($menu,0,array('menu-item-title'=>$row[0],'menu-item-type'=>'custom','menu-item-url'=>$row[2]==='lottery'?home_url('/#'.$row[4]):get_theme_mod('mm889_'.$row[2],home_url('/')),'menu-item-status'=>'publish','menu-item-position'=>$n+1));if(!is_wp_error($id)){foreach(array('icon'=>1,'role'=>2,'look'=>3,'anchor'=>4) as $field=>$index){update_post_meta($id,'_mm889_'.$field,$row[$index]);}}}$locations[$location]=$menu;}set_theme_mod('nav_menu_locations',$locations);update_option('mm889_flexible_setup_v1',1,false);
},30);
function mm889_palette(){return array(
    'background'=>array('พื้นหลังเว็บไซต์','#003323'),'background2'=>array('พื้นหลังไล่สีปลายทาง','#002b20'),'accent'=>array('สีเน้น / เส้นขอบ / ทอง','#e4bc58'),'shine'=>array('สีอ่อนของปุ่มและสีทอง','#ffedba'),'text'=>array('ตัวอักษรหลัก','#fff8e8'),'muted'=>array('ตัวอักษรรอง','#b7cbb8'),
    'header'=>array('หัวเว็บ สีเริ่มต้น','#005c3d'),'header2'=>array('หัวเว็บ สีปลายทาง','#008258'),'sidebar'=>array('เมนูซ้าย สีเริ่มต้น','#00603b'),'sidebar2'=>array('เมนูซ้าย สีปลายทาง','#003c2b'),'card'=>array('การ์ดหวย สีเริ่มต้น','#08754c'),'card2'=>array('การ์ดหวย สีปลายทาง','#005034'),'button'=>array('ปุ่มปกติ สีเริ่มต้น','#087c53'),'button2'=>array('ปุ่มปกติ สีปลายทาง','#005a3b'),'button_text'=>array('ตัวอักษรบนปุ่มสีเน้น','#143b24'),
    'mobile'=>array('แถบเมนูล่างมือถือ','#003c2d'),'footer'=>array('พื้นหลังฟุตเตอร์','#002b20'),'popup'=>array('ป๊อปอัป สีเริ่มต้น','#00613f'),'popup2'=>array('ป๊อปอัป สีปลายทาง','#002e23'),'article'=>array('กล่องเนื้อหาหน้าและบทความ','#fffdf5'),'article_text'=>array('ตัวอักษรในหน้าและบทความ','#203c30')
);}
add_action('customize_register',function($c){
    $c->add_section('mm889_design',array('title'=>'มั่งมี889 — สีและพื้นหลัง','priority'=>32,'description'=>'เปลี่ยนสีแต่ละส่วนได้ อัปโหลดพื้นหลังเอง หรือปิดลวดลายพื้นหลังได้ โลโก้และรูปแบนเนอร์เป็นรูปภาพ สีภายในรูปจะไม่ถูกเปลี่ยนตามชุดสี'));
    foreach(mm889_palette() as $key=>$data){$setting='mm889_color_'.$key;$c->add_setting($setting,array('default'=>$data[1],'sanitize_callback'=>'sanitize_hex_color'));$c->add_control(new WP_Customize_Color_Control($c,$setting,array('label'=>$data[0],'section'=>'mm889_design')));}
    $c->add_setting('mm889_pattern',array('default'=>true,'sanitize_callback'=>function($v){return (bool)$v;}));$c->add_control('mm889_pattern',array('type'=>'checkbox','label'=>'แสดงลวดลายพื้นหลัง','section'=>'mm889_design'));
    $c->add_setting('mm889_background_image',array('default'=>'','sanitize_callback'=>'esc_url_raw'));$c->add_control(new WP_Customize_Image_Control($c,'mm889_background_image',array('label'=>'รูปพื้นหลังของคุณ','section'=>'mm889_design')));
    $c->add_setting('mm889_lottery_page',array('default'=>0,'sanitize_callback'=>'absint'));$c->add_control('mm889_lottery_page',array('type'=>'dropdown-pages','label'=>'หน้าที่ใช้ดีไซน์รวมรายการหวย','description'=>'เลือกหน้าแรกหลักที่ ตั้งค่า → การอ่าน ส่วนหน้านี้ใช้เก็บดีไซน์รวมรายการหวยเดิม','section'=>'static_front_page'));
});
add_action('wp_head',function(){
    $v=array();$changed=false;foreach(mm889_palette() as $key=>$data){$v[$key]=sanitize_hex_color(get_theme_mod('mm889_color_'.$key,$data[1]))?:$data[1];if($v[$key]!==$data[1]){$changed=true;}}
    echo '<style id="mm889-editable-navigation">.side-nav{gap:9px}.side-nav .mm-menu-icon{width:42px;height:42px;flex:none;display:grid;place-items:center}.mm-menu-icon svg{width:27px;height:27px}.side-nav .mm-menu-icon img{width:42px;height:42px}.side-nav .side-link{width:100%;text-align:left;color:inherit}.side-nav .mm-menu-gold{background:linear-gradient(100deg,var(--gold),var(--cream),var(--gold));color:var(--deep);border-color:var(--cream)}@media(max-width:700px){body .mobile-nav{grid-template-columns:none;grid-auto-flow:column;grid-auto-columns:minmax(64px,1fr);overflow-x:auto;overflow-y:hidden}body .mobile-nav>a,body .mobile-nav>button{display:grid;grid-template-rows:24px auto;line-height:1.4;font-size:11px;gap:4px;text-align:center}body .mobile-nav>:nth-child(n):before{content:none!important}.mobile-nav .mm-menu-icon{width:24px;height:24px;display:grid;place-items:center}.mobile-nav .mm-menu-icon img,.mobile-nav .mm-menu-icon svg{width:24px;height:24px}.mobile-nav .mm-menu-label{white-space:normal}.mobile-nav .mm-menu-gold{color:var(--cream)}}';
    if($changed){
        echo ':root{--gold:'.$v['accent'].';--cream:'.$v['shine'].';--green:'.$v['card'].';--deep:'.$v['background2'].';--line:'.$v['accent'].'}body{background:'.$v['background'].';color:'.$v['text'].'}body .site-header{background:linear-gradient(110deg,'.$v['header'].','.$v['header2'].');border-color:'.$v['accent'].'}body .stage:before{background:linear-gradient(120deg,'.$v['background'].'dd,'.$v['background2'].'bb),url("'.esc_url(get_theme_mod('mm889_background_image')?:get_template_directory_uri().'/assets/pattern.svg').'") center/630px}body .stage:after{background:linear-gradient(180deg,transparent 60%,'.$v['background2'].')}body .sidebar{background:linear-gradient(150deg,'.$v['sidebar'].','.$v['sidebar2'].');border-color:'.$v['accent'].'}body .side-link,body .category{background:linear-gradient(130deg,'.$v['sidebar'].','.$v['sidebar2'].');border-color:'.$v['accent'].';color:'.$v['text'].'}body .lotto-card{background:linear-gradient(130deg,'.$v['card'].','.$v['card2'].');border-color:'.$v['accent'].';color:'.$v['text'].'}body .btn{background:linear-gradient('.$v['button'].','.$v['button2'].');color:'.$v['text'].'}body .btn.gold,body .category.active span,body .side-nav .mm-menu-gold,body .section-heading span,body .mm-shortcut-icon{background:linear-gradient(110deg,'.$v['accent'].','.$v['shine'].','.$v['accent'].');color:'.$v['button_text'].';border-color:'.$v['accent'].'}body .category.active{background:linear-gradient(130deg,'.$v['card'].','.$v['card2'].');box-shadow:0 0 0 4px '.$v['accent'].';border-color:'.$v['shine'].'}body .mobile-nav{background:'.$v['mobile'].';border-color:'.$v['accent'].'}body .mobile-nav a,body .mobile-nav button{color:'.$v['shine'].'}body .site-footer{background:'.$v['footer'].';border-color:'.$v['accent'].'55;padding:18px;border-radius:12px}body .site-footer b,body .card-arrow,body .lotto-card .round,body .dialog-kicker,body dialog h2{color:'.$v['shine'].'}body dialog{background:linear-gradient(135deg,'.$v['popup'].','.$v['popup2'].');border-color:'.$v['accent'].';color:'.$v['text'].'}body dialog p,body .content-title p,body .side-note,body .page-note,body .mm-shortcuts-heading>span,body .mm-shortcut-copy small{color:'.$v['muted'].'}body .mm-shortcut,body .mm-hero{background:'.$v['card2'].';border-color:'.$v['accent'].'}body .mm-shortcuts-heading h2{color:'.$v['shine'].'}body .article-content{background:'.$v['article'].';color:'.$v['article_text'].';border-color:'.$v['accent'].'}body .article-content h1,body .article-content a{color:'.$v['article_text'].'}';
    }
    $image=get_theme_mod('mm889_background_image','');if($image && !$changed){echo 'body .stage:before{background-image:linear-gradient(120deg,#002d2040,#00382530),url("'.esc_url($image).'");background-size:cover;background-position:center}';}
    if(!get_theme_mod('mm889_pattern',true)){echo 'body .stage:before{background:linear-gradient(120deg,'.$v['background'].','.$v['background2'].')}';}
    echo '</style>';
},100);
